Around and Inner Cell Borders

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
833
Hi Guys

I am selecting ranges and then want to automate adding Borders and BordersAround the selected range. When running the code, I have to call the macro twice to do BordersAround and Border on the selected cells. Looking for some help in order that I can call the macro once and get both.

VBA Code:
Sub Frame()

With Selection.Borders.LineStyle = xlContinuous
    End With
With Selection.BorderAround.xlContinuous.xlThick
    End With
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
VBA Code:
Sub Frame()

Selection.Borders.LineStyle = xlContinuous

Selection.BorderAround xlContinuous, xlThick

End Sub
 
Upvote 0
How about
VBA Code:
Sub Frame()

Selection.Borders.LineStyle = xlContinuous

Selection.BorderAround xlContinuous, xlThick

End Sub
Hi Fluff

Applied your code. I am still having to run the code twice to get Borders and BordersAround.
 
Upvote 0
You shouldn't need to. Are you running that code on it's own, or is it part of a larger macro?
 
Upvote 0
Hi Fluff, its being run on its own. I have stepped through it, it executes ok. But, depending on which code is hit first in the macro, the BorderAround or Borders if I change the order, this is applied. Run the same code again, the secondary code updates the selected range.

Based on your code, I have taken a step back and looked at the worksheet. I have added an additional line in and your code is adding both.

VBA Code:
Sub Frame()
Selection.Borders.LineStyle = xlNone

Selection.Borders.LineStyle = xlContinuous

Selection.BorderAround xlContinuous, xlThick

End Sub
 
Last edited:
Upvote 0
Solution
Why are you changing the order of the code, leave it as it is.
 
Upvote 0
Why are you changing the order of the code, leave it as it is.
Hi Fluff, I changed the order to see if it made any difference. See my last post for resolving the issue. Thanks for your
input, its frustrated me this afternoon.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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