Worksheet Name Does Not Contain

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
Hi All, I have a script that copies each sheet in a workbook into its own workbook. I am trying to exclude sheets that contain "EEs" and can't seem to get it to recognize this. Any thoughts? Below is my current code:

Code:
Sub SplitEachWorksheetDepReport()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each ws In ThisWorkbook.Sheets

If ws.Name Like "EEs*" = False And ws.Name <> "Master" And ws.Name <> "Controls" And ws.Name <> "Check Returns" Then
    ws.Copy
    Application.ActiveWorkbook.SaveAs Filename:="C:\User" & "\" & ws.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Complete"
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do the sheet names contain, or start with EEs?
 
Upvote 0
Is this what you are trying?

If sheet name starts with EEs then use

VBA Code:
For Each ws In ThisWorkbook.Sheets
    If Not ws.Name Like "EEs*" And ws.Name <> "Master" And _
    ws.Name <> "Controls" And ws.Name <> "Check Returns" Then
        '
        '~~> Your code
        '
    End If
Next ws

If sheet name contains that word then use the below.

VBA Code:
For Each ws In ThisWorkbook.Sheets
    If InStr(1, ws.Name, "EEs", vbTextCompare) = 0 And ws.Name <> "Master" And _
    ws.Name <> "Controls" And ws.Name <> "Check Returns" Then
        '
        '~~> Your code
        '
    End If
Next ws
 
Upvote 0
Solution
Awesome, the second suggestion worked (for if the worksheet contains and does not start with). Thanks!
 
Upvote 0
If you are looking for contains you could also use
VBA Code:
If ws.Name Like "*EEs*" = False And ws.Name <> "Master" And ws.Name <> "Controls" And ws.Name <> "Check Returns" Then
you just need the extra * at the start of the string.
 
Upvote 0

Forum statistics

Threads
1,215,688
Messages
6,126,210
Members
449,299
Latest member
KatieTrev

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