VBA Borders to Last Row Plus 10 Additional Rows

rsmeyerson

Board Regular
Joined
Nov 29, 2014
Messages
104
I'll looking for help with adding borders to all non-empty rows plus 10 additional rows. Here is my code below that already adds borders to all used rows. Can you please help me modify it to add the next 10 rows beneath the last row?

In addition, I need to add medium weight borders to certain columns that I'm currently adding line by line in my code below. Is there a way to do this with multiple columns within the same line of code?

Thanks for your help,

Bob

Code:
Sheets("Master").Select
last = Cells(Rows.Count, "A").End(xlUp).Row
    For i = last To 4 Step -1
            Cells(i, "A").Resize(, 77).Borders.LineStyle = xlContinuous
            Cells(i, "G").Borders(xlEdgeLeft).Weight = xlMedium
            Cells(i, "Q").Borders(xlEdgeLeft).Weight = xlMedium
            Cells(i, "AA").Borders(xlEdgeLeft).Weight = xlMedium
    Next i
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You shouldn't need a loop and that can be reduced to this:

Code:
last = Cells(Rows.Count, "A").End(xlUp).Row
With Range("A4:A" & last).Resize(last + 7, 77)
    .Borders.LineStyle = xlContinuous
    Union(.Columns(7), .Columns(17), Columns(27)).Borders(xlEdgeLeft).Weight = xlMedium
End With
 
Upvote 0
Thank you! This works perfectly. Can you please tell me what part of this code adds borders to last row plus 10? I see last + 7 in your code.
 
Upvote 0
I have one last question please. The code you gave me for the left edge medium weight border is working correctly for columns 7 and 17, but for column 37 and any additional columns I add further to the right, the borders are not stopping at the last row. They are continuing indefinitely. Do you see why this might be occurring?
 
Upvote 0
This is: last + 7, it's adjusted for the fact that you are not starting on row 1.

Try this instead:

Code:
Sub test()
Dim last As Long
last = Cells(Rows.Count, "A").End(xlUp).Row
With Range("A4:A" & last).Resize(last + 7, 77)
    .Borders.LineStyle = xlContinuous
    Intersect(Rows(4).Resize(last + 7), Union(.Columns(7), .Columns(17), Columns(27), Columns(37))).Borders(xlEdgeLeft).Weight = xlMedium
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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