L
Legacy 347042
Guest
Hi
I've been recording some basic formatting macros to speed up my work. I am wanting some to cycle to different formats depending on the existing format of selected cells. For example, I have the following code for including a top border on the selection:
Private Sub Top_Border()'
' Top_Border Macro
'
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
And the following code for including a top and a bottom border on a cell:
Private Sub Double_Border()
'
' Double_Border Macro
'
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
But what I am wanting is for when I run the macro, if there is no top border, then include the top border, if there is already a top border, then include both a top and a bottom border, and if there is already a top and bottom border, then remove both of the borders. I am just looking to utilise similar functions whilst using minimal keyboard short-cuts.
I know this is probably basic and that the above code is possibly very clunky - but I am a VBA novice!
Thanks!
I've been recording some basic formatting macros to speed up my work. I am wanting some to cycle to different formats depending on the existing format of selected cells. For example, I have the following code for including a top border on the selection:
Private Sub Top_Border()'
' Top_Border Macro
'
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
And the following code for including a top and a bottom border on a cell:
Private Sub Double_Border()
'
' Double_Border Macro
'
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
But what I am wanting is for when I run the macro, if there is no top border, then include the top border, if there is already a top border, then include both a top and a bottom border, and if there is already a top and bottom border, then remove both of the borders. I am just looking to utilise similar functions whilst using minimal keyboard short-cuts.
I know this is probably basic and that the above code is possibly very clunky - but I am a VBA novice!
Thanks!