Toggle X On and Off

miketurn

Active Member
Joined
Dec 8, 2016
Messages
268
Hello Everyone,

Not an extremely needed tool but I feel that there will be some that will find this useful.

I was able to record the following two macros below (seems like so much coding for something so simple).
The first one adds an X (using diagonal Borders lines) to selected cells and the second one removes this X from selected cells.

I was wondering if someone would be able to combine these two into one macro using "IF" syntax.
So if there isn't an X this macro will add it to the selected cell(s) and if an X does exist in the selected cell(s) remove it.

I tried adding the "if" and the "else" myself but yeah I don't know what I am doing :)


Adds X
Code:
Sub AddX() 
    With Selection.Borders(xlDiagonalDown) 
        .LineStyle = xlContinuous 
        .Weight = xlMedium 
        .ColorIndex = xlAutomatic 
    End With 
    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 
    With Selection.Borders(xlDiagonalDown) 
        .LineStyle = xlContinuous 
        .Weight = xlMedium 
        .ColorIndex = xlAutomatic 
    End With 
    With Selection.Borders(xlDiagonalUp) 
        .LineStyle = xlContinuous 
        .Weight = xlMedium 
        .ColorIndex = xlAutomatic 
    End With 
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone 
    Selection.Borders(xlEdgeTop).LineStyle = xlNone 
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone 
    Selection.Borders(xlEdgeRight).LineStyle = xlNone 
End Sub


Removes X
Code:
Sub RemoveX() 
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
    With Selection.Borders(xlDiagonalUp) 
        .LineStyle = xlContinuous 
        .Weight = xlMedium 
        .ColorIndex = xlAutomatic 
    End With 
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone 
    Selection.Borders(xlEdgeTop).LineStyle = xlNone 
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone 
    Selection.Borders(xlEdgeRight).LineStyle = xlNone 
    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 
End Sub
 
Last edited:
@mikerickson
Common sense thing I overlooked, that makes perfect sense. Thank You very much for the macro, the style setup code, and for your recent explanation, you have been very helpful.

@Logit
Thank You for your response and for providing this macro, cool idea, I keep forgetting that you can edit double clicks, but the only thing is some times force of habit I double click to enter cells, so it would only be a matter of time :)
But I will probably set this up to use from time to time, so thank you again for this.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
But ... the macro allows you to double-click again to get rid of the X.

:eek: waaaaat !!?
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,262
Members
448,953
Latest member
Dutchie_1

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