WS looping

urchino

New Member
Joined
Sep 29, 2015
Messages
11
Dear Experts

I search through the forum and tried to improvise but it seems it is not working.
Wish to repeat a macro through different sheet name but the looping only on the first sheet.

VBA Code:
Sub Test()
Dim Sh As Worksheet
    For Each Sh In ActiveWorkbook.Worksheets
        If Sh.Name <> "Inp*" Then
            With Sh
                    Dim c As Range
                        For Each c In Range("1:1").Cells
                            If c.Value = "Lock" Then
                            c.EntireColumn.Select
                    Selection.Locked = True
        End If
    Next c
            End With
        End If
    Next Sh
End Sub

Any help would be great. Thank you. Appreciate it.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
pls see if below helps

VBA Code:
Sub Test()
    Dim Sh As Worksheet
    For Each Sh In ActiveWorkbook.Worksheets
        If Left(Sh.Name, 3) <> "Inp" Then ' Check if the sheet name doesn't start with "Inp"
            Dim c As Range
            For Each c In Sh.Range("1:1").Cells ' Specify the range for the current worksheet
                If c.Value = "Lock" Then
                    c.EntireColumn.Locked = True
                End If
            Next c
        End If
    Next Sh
End Sub
 
Upvote 0
pls see if below helps

VBA Code:
Sub Test()
    Dim Sh As Worksheet
    For Each Sh In ActiveWorkbook.Worksheets
        If Left(Sh.Name, 3) <> "Inp" Then ' Check if the sheet name doesn't start with "Inp"
            Dim c As Range
            For Each c In Sh.Range("1:1").Cells ' Specify the range for the current worksheet
                If c.Value = "Lock" Then
                    c.EntireColumn.Locked = True
                End If
            Next c
        End If
    Next Sh
End Sub
Works perfectly. Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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