ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   toggle borders macro (https://www.excelbanter.com/excel-programming/403175-toggle-borders-macro.html)

pwilson.bowdoin

toggle borders macro
 
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

joel

toggle borders macro
 
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


"pwilson.bowdoin" wrote:

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


pwilson.bowdoin

toggle borders macro
 
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

joel

toggle borders macro
 
I just wanted to give you some ideas so you could solve your own problem.

"pwilson.bowdoin" wrote:

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



All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com