Macro to run on multiple selected sheets

danjw_98

Active Member
Joined
Oct 25, 2003
Messages
354
I am trying to get the below macro to run on multiple selected worksheets and can't seem to get it working. Would appreciate any support on this. thanks...

Dim wrkSheet As Worksheet

For Each wrkSheet In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))


lastrow = Range("g65536").End(xlUp).Row
For x = 2 To lastrow

Set rng = Range("A" & x & ":H" & x)

With rng
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlThin
End With


Next x
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Dim wrkSheet As Worksheet

For Each wrkSheet In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
    With wrkSheet
    
        lastrow = .Range("g65536").End(xlUp).Row
        For x = 2 To lastrow
        
            Set Rng = .Range("A" & x & ":H" & x)
            
            With Rng
                .Borders(xlEdgeTop).Weight = xlThin
                .Borders(xlEdgeBottom).Weight = xlThin
                .Borders(xlEdgeLeft).Weight = xlThin
                .Borders(xlEdgeRight).Weight = xlThin
                .Borders(xlInsideVertical).Weight = xlThin
            End With
        
        
        Next x
    End With
Next wrkSheet
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,983
Messages
5,856,659
Members
431,827
Latest member
dbonser

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