Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with xlInsideHorizontal border vba

Status
Not open for further replies.

DrSmyth

Technical User
Jul 16, 2003
557
GB
Hi,

I've got a spreadsheet that people are using as a diary, the user will simply select a series of cells (in a column) and then click on a button to add an activity, each cell in a column represents half an hour.

The problem i've got is with the code i've created to reset the diary, basically people select an activity they have added and can remove it by clicking on a button and running this code.

The problem arises when the activity is only half an hour (1 cell) long. the code is breaking down on the xlInsideHorizontal properties line (obviously a single cell will not have any inside horizontal lines.....

Can anybody suggest an alternative? My code for the whole routine is as follows:

Code:
Selection.ClearContents
    With Selection
     .MergeCells = False
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlDot
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlDot
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlDot
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlDot
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    [b]With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlDot
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With[/b]
    With Selection.Interior
        .ColorIndex = 2
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
    End With
End Sub

It's driving me nuts, was thinking of giving it a bit of logic to see if there is an inside horizontal line, but not sure if this would work or even how to code something like this...

Thanks for any help

Dr
 
Hi there if you just insert on error resume next at the start of your procedure it will just skip over this section if it doesn't work

hope this helps
 
Cheers Rivet, seems to have done the trick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top