How to find last row and Add A Border

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hello Guys,

I have workbook with Sheets 1 to 10. For each sheet, I need to find the last row, delete the excess vertical lines below it (just CTRL+DELETE). Below the last row, I need to add a vertical border by just copying the border that can be found on A3-AC3 across all sheets. Thanks in advance for all the help.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this

VBA
- in the first 10 sheets in the workbook (regardless of name)
- finds last row
- deletes borders below that row
(I need to find the last row, delete the excess vertical lines below it)
- copies all formatting including borders fron A3:AC3 into row below last row
(Below the last row, I need to add a vertical border by just copying the border that can be found on A3-AC3 across all sheets)

Code:
Sub AddBorder()
    Application.ScreenUpdating = False:     Application.Calculation = xlCalculationManual
    Dim w As Integer, lr As Long
    For w = 1 To 10
        With Sheets(w)
            .Activate
            lr = .Cells(Rows.Count, 1).End(xlUp).Row
            .Rows(lr & ":" & Rows.Count).Borders.LineStyle = xlLineStyleNone
                With .Range("A3:AC3")
                    .Copy
                    .Offset(lr + 1 - 3).PasteSpecial Paste:=xlPasteFormats
                End With
            Application.Goto Reference:=Range("A" & lr), Scroll:=True
        End With
    Next w
    Application.ScreenUpdating = True:      Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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