Adding Outside Border Around a Dynamic Range of Columns and Rows

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm trying to add an outside border to a range of cells that starts at a constant cell (A7), but extends down a variable number of rows and across a variable number of columns. The Excel spreadsheet will be different in terms of rows & columns each day, so I want to add this part to my formatting macro that can do it automatically. Can anyone point me in the right direction? I've seen various examples for dynamic rows. For example, I have this within my own macro earlier after adding a new column and doing a formula fill down:

Code:
With Range("B8:B" & Range("B" & Rows.Count).End(xlUp).Row).Borders
         .LineStyle = xlContinuous
         .Weight = xlMedium

I would try to adapt this to add an outside border after doing some more formatting, but I don't know how to account for the dynamic number of columns.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe...
Code:
[table="width: 500"]
[tr]
	[td]LastUsedRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious, , , False).Row
LastUsedCol = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
With Range("A7", Cells(LastUsedRow, LastUsedCol))
  etc.[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
The Weight argument of .BorderAround can be set as desired.

When I switched the weight argument to medium, I ended up losing the border I had around my entire range. When it was set to linestyle = xlContinuous, I had a thin border, but when I replaced it with weight = xlMedium, it didn't fill in all the border gaps I was trying to fill in with anything at all.
 
Upvote 0
Never mind, I was able to figure it out. Thanks so much for your help!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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