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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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