Macro to toggle -bottom border, all borders, thick border, no border

Xx7

Board Regular
Joined
Jan 29, 2011
Messages
126
I would appreciate a macro that puts the following borders on the selection:

Run once
Bottom border

Run again
All borders

Run again
Thick border

Run again
No border

Run again
Bottom border

...then repeat the cycle
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello

Try.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> test()<br>  <SPAN style="color:#00007F">Static</SPAN> a <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br>  <SPAN style="color:#00007F">With</SPAN> Selection<br>    <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> a<br>      <SPAN style="color:#00007F">Case</SPAN> 0 <SPAN style="color:#007F00">'Bottom border</SPAN><br>        .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>        .Borders(xlEdgeBottom).Weight = xlThin<br>      <SPAN style="color:#00007F">Case</SPAN> 1 <SPAN style="color:#007F00">'All borders</SPAN><br>        .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>        .Borders.Weight = xlThin<br>      <SPAN style="color:#00007F">Case</SPAN> 2 <SPAN style="color:#007F00">'Thick border</SPAN><br>        .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>        .BorderAround ColorIndex:=xlAutomatic, Weight:=xlThick<br>      <SPAN style="color:#00007F">Case</SPAN> 3 <SPAN style="color:#007F00">'No border</SPAN><br>        .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>     <SPAN style="color:#00007F">End</SPAN> Select<br>   <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>  a = a + 1<br>  <SPAN style="color:#00007F">If</SPAN> a > 3 <SPAN style="color:#00007F">Then</SPAN> a = 0<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Nice... :) Is there anyway to identify the current border selection and then scroll through.

Eg. If I go to a selection and it is currently "all borders". Then I would prefer that it identify this and when the macro is run it will go to "thick border" instead of starting at the beginning of the process which is "bottom border"

Can this be accomplished? :confused:
 
Upvote 0
Hi there

Try this one.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> test2()<br>  <SPAN style="color:#00007F">With</SPAN> Selection<br>    <SPAN style="color:#00007F">If</SPAN> .Borders.LineStyle = xlNone <SPAN style="color:#00007F">Then</SPAN><br>      .Borders(xlEdgeBottom).Weight = xlThin<br>    <SPAN style="color:#00007F">ElseIf</SPAN> .Borders(xlEdgeBottom).Weight = xlThin And _<br>        .Borders(xlEdgeTop).LineStyle = xlNone <SPAN style="color:#00007F">Then</SPAN><br>      .Borders.Weight = xlThin<br>    <SPAN style="color:#00007F">ElseIf</SPAN> .Borders.Weight = xlThin <SPAN style="color:#00007F">Then</SPAN><br>      .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>      .BorderAround ColorIndex:=xlAutomatic, Weight:=xlThick<br>    <SPAN style="color:#00007F">Else</SPAN><br>      .Borders.LineStyle = xlNone <SPAN style="color:#007F00">'Clear All</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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