VBA Help: Loop thru each tab EXCEPT those that start with letters...

losamfr17

Board Regular
Joined
Jun 10, 2016
Messages
149
Good morning dear wizards.

Can I please get some guidance on this dilemma?

I want to run the code below ONLY on worksheets whose names DO NOT START with "ULT".
Some tab names are all letters, numbers, or both letters and numbers. Is there a way to do that please?

Code:
Sub UNprotect_All_Sheets()


    Dim ws As Worksheet
        
    For Each ws In ActiveWorkbook.Worksheets
        ws.Unprotect Password:="adminf18"
    Next ws
    
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Re: VBA: If with OR code won't work - Please help

It should work if you edit your original code, changing "Or" to "And" like this, and fix the error in your original code.

It should be:
Code:
Left(ws.Name, [COLOR=#ff0000][B]4[/B][/COLOR]) <> "HOME"
not:
Code:
[COLOR=#333333]Left(ws.Name, [/COLOR][COLOR=#ff0000][B]3[/B][/COLOR][COLOR=#333333]) <> "HOME"[/COLOR]

So your code should look like:
Code:
Sub ETS_All_Sheets()

    Dim ws As Worksheet
       
    For Each ws In ActiveWorkbook.Worksheets
        If ((Left(ws.Name, 3) <> "ULT") [COLOR=#ff0000][B]And[/B][/COLOR] (Left(ws.Name, 4) <> "HOME")) Then
            ws.Range("M4").Value = "Oui"
        End If
    Next ws
    
End Sub
 
Last edited:
Upvote 0
@losamfr17
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. (rule 12 here: Forum Rules).
I have merged both your threads.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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