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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,083
Messages
5,599,643
Members
414,326
Latest member
kfg1287

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