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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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