Border active cell range

jamada

Active Member
Joined
Mar 23, 2006
Messages
323
Hi

I have the following code, that works excellent for the workbook, however I would like to limit it to only the "active page" and cannot seem to get it, can anyone suggest a way.

For Each ws In ActiveWorkbook.Worksheets
LastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A7:F" & LastRow).Borders.Weight = xlThin
Next ws


Tks Jamada
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try replacing that with

Code:
LastRow = Range("A" & ws.Rows.Count).End(xlUp).Row
Range("A7:F" & LastRow).Borders.Weight = xlThin
 
Upvote 0
Try...
Code:
 Range("A7:F" & Range("A" & Rows.Count).End(xlUp).Row).Borders.Weight = xlThin

Edit: just saw Vog's post but leaving the post here as slightly different method.
2nd Edit: actually I think the ws in VoG's post should be removed but shouldn't actually make a difference.
Code:
Range("A" & [COLOR="#FF0000"]ws.[/COLOR]Rows.Count).End(xlUp).Row
 
Last edited:
Upvote 0
VoG...... Tks but I ended up with a Run-time errorr424 Object Required... maybe my code was missing something.

MARK 858s response fir in well though.
Thank You, especially for the quick response.
Jamada
 
Upvote 0
Silly me - I left in a ws.

Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A7:F" & LastRow).Borders.Weight = xlThin
 
Upvote 0
Silly me - I left in a ws.

Rich (BB code):
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A7:F" & LastRow).Borders.Weight = xlThin

Since your code would be inside the OP's For..Each..Next loop, I think the ws should be placed in front of both Ranges...

Code:
LastRow = [B]ws.[/B]Range("A" & Rows.Count).End(xlUp).Row
[B]ws.[/B] Range("A7:F" & LastRow).Borders.Weight = xlThin
 
Upvote 0
Since your code would be inside the OP's For..Each..Next loop, I think the ws should be placed in front of both Ranges...

Code:
LastRow = [B]ws.[/B]Range("A" & Rows.Count).End(xlUp).Row
[B]ws.[/B] Range("A7:F" & LastRow).Borders.Weight = xlThin

I think not - I said to replace the original with my 2 lines of code.
 
Upvote 0

Forum statistics

Threads
1,214,660
Messages
6,120,787
Members
448,994
Latest member
rohitsomani

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