P
pwilson.bowdoin
I am trying to create a macro that toggles borders around a cell. If
the cell has no borders, then the macro will place a border on the
topedge. If there is a top border, then the macro will remove the top
border and add a border on the right edge. This is what I have and it
is not working and I'm not sure why. Thanks for the help!
Sub ToggleBorder()
With Selection
If .Borders(xlEdgeTop).LineStyle = xlNone _
And .Borders(xlEdgeRight).LineStyle = xlNone _
And .Borders(xlEdgeBottom).LineStyle = xlNone _
And .Borders(xlEdgeLeft).LineStyle = xlNone _
Then .Borders(xlEdgeTop).LineStyle = xlContinuous _
Else
If .Borders(xlEdgeTop).LineStyle = xlContinuous _
And .Borders(xlEdgeRight).LineStyle = xlNone _
And .Borders(xlEdgeBottom).LineStyle = xlNone _
And .Borders(xlEdgeLeft).LineStyle = xlNone _
Then .Borders(xlEdgeRight).LineStyle = xlContinuous _
And .Borders(xlEdgeTop).LineStyle = xlNone_
End With
End Sub
the cell has no borders, then the macro will place a border on the
topedge. If there is a top border, then the macro will remove the top
border and add a border on the right edge. This is what I have and it
is not working and I'm not sure why. Thanks for the help!
Sub ToggleBorder()
With Selection
If .Borders(xlEdgeTop).LineStyle = xlNone _
And .Borders(xlEdgeRight).LineStyle = xlNone _
And .Borders(xlEdgeBottom).LineStyle = xlNone _
And .Borders(xlEdgeLeft).LineStyle = xlNone _
Then .Borders(xlEdgeTop).LineStyle = xlContinuous _
Else
If .Borders(xlEdgeTop).LineStyle = xlContinuous _
And .Borders(xlEdgeRight).LineStyle = xlNone _
And .Borders(xlEdgeBottom).LineStyle = xlNone _
And .Borders(xlEdgeLeft).LineStyle = xlNone _
Then .Borders(xlEdgeRight).LineStyle = xlContinuous _
And .Borders(xlEdgeTop).LineStyle = xlNone_
End With
End Sub