Around and Inner Cell Borders

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,890
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Sub Frame()

Selection.Borders.LineStyle = xlContinuous

Selection.BorderAround xlContinuous, xlThick

End Sub
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,890
Office Version
  1. 365
Platform
  1. Windows
You shouldn't need to. Are you running that code on it's own, or is it part of a larger macro?
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817

ADVERTISEMENT

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:
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,890
Office Version
  1. 365
Platform
  1. Windows
Why are you changing the order of the code, leave it as it is.
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,890
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

Forum statistics

Threads
1,144,162
Messages
5,722,842
Members
422,460
Latest member
VBA_Noob01

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
Top