How do you write VBA that removes the "Double-Bottom Edge" border formatting?

awcw88

New Member
Joined
Jul 24, 2012
Messages
3
I wrote the following VBA macro that cycles through different border formats each time a unique keyboard shortcut is pressed. It is supposed to progress from a thin solid bottom border, to a thick solid bottom border, to a double-line bottom border, then return to "no border." It works as intended except for the last step. I can write the macro such that it goes from a thick, solid bottom border to no border, but following the same logic doesn't work when trying to go from the double-line bottom border to no border.

Please advise.

Sub borderCycle()
' borderCycle Macro
' Macro recorded 1/17/2012 by wongand1
' Keyboard Shortcut: Ctrl+Shift+B

With Selection


'//Add thin solid bottom border
If (Selection.Borders(xlEdgeBottom).LineStyle = xlNone) Then
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).Weight = xlThin
Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic


'//Add thick solid bottom border
ElseIf (Selection.Borders(xlEdgeBottom).Weight = xlThin) Then
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).Weight = xlThick
Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic

'//Add thick double bottom border
ElseIf (Selection.Borders(xlEdgeBottom).Weight = xlThick) Then
Selection.Borders(xlEdgeBottom).LineStyle = xlDouble
Selection.Borders(xlEdgeBottom).Weight = xlThick
Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic




' //(trying to remove thick, double bottom edge border)
ElseIf (Selection.Borders(xlEdgeBottom).LineStyle = xlDouble) Then
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone​
Selection.Borders(xlEdgeLeft).LineStyle = xlNone​
Selection.Borders(xlEdgeTop).LineStyle = xlNone​
Selection.Borders(xlEdgeBottom).LineStyle = xlNone​
Selection.Borders(xlEdgeRight).LineStyle = xlNone​
Selection.Borders(xlInsideVertical).LineStyle = xlNone​
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone​
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe ...

Code:
Sub borderCycle()
    Dim r As Range
    
    Set r = ActiveWindow.RangeSelection
    
    With r.Borders(xlEdgeBottom)
        If .LineStyle = xlNone Then
            .LineStyle = xlContinuous
            .Weight = xlThin
        ElseIf .Weight = xlThin Then
            .Weight = xlThick
        ElseIf .Weight = xlThick And .LineStyle <> xlDouble Then
            .LineStyle = xlDouble
        ElseIf .LineStyle = xlDouble Then
            .LineStyle = xlNone
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,823
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top