toggle borders macro

P

pwilson.bowdoin

I'm trying to create a macro that will cycle between border options.
(edgetop, edgeright,edgebottom, edgeleft, outline cell)

I have been trying to do this using the select case function but have
been unsuccessful. Is it possible to have multiple prerequisites with
the select case function?

My main problem is dealing with the (xlEdgetop) modifier in the select
case function.

Thanks for the help1

Sub ToggleBorders()
With Selection
Select Case .Borders.LineStyle
Case xlNone
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
End Select
End With
End Sub
 
J

Joel

Try this

Public Enum borderStyle
TopCell = 1
LeftCell = 2
TopCornerCell = 3
End Enum

Sub ToggleBorders()
With Selection
If .Row = 1 And .Column = 1 Then
MyStyle = TopCornerCell
Else
If .Row = 1 And .Column = 1 Then
MyStyle = TopCornerCell
End If
If .Row = 1 And .Column = 1 Then
MyStyle = TopCornerCell
End If
End If
Select Case MyStyle

Case TopCell
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
End Select
End With
End Sub

Another method

Sub ToggleBorders()
With Selection
For Edge = xlDiagonalDown To xlInsideVertical
Case xlDiagonalDown '=5
.Borders(Edge).LineStyle = xlContinuous
Case xlDiagonalUp '=6
Case xlEdgeLeft '=7
Case xlEdgeTop '=8
Case xlEdgeBottom '=9
Case xlEdgeRight '=10
Case xlInsideHorizontal '=11
Case xlInsideVertical '=12
Next edge
End With
End Sub
 
P

pwilson.bowdoin

For the second method don't we need a select case function to agree
with the Case's below. The method which I'm referring to is below.
Thanks for the help!


Sub ToggleBorders()
With Selection
For Edge = xlDiagonalDown To xlInsideVertical
Case xlDiagonalDown '=5
.Borders(Edge).LineStyle = xlContinuous
Case xlDiagonalUp '=6
Case xlEdgeLeft '=7
Case xlEdgeTop '=8
Case xlEdgeBottom '=9
Case xlEdgeRight '=10
Case xlInsideHorizontal '=11
Case xlInsideVertical '=12
Next edge
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top