Finding Sheet Names starting with #

stuartgb100

Active Member
Joined
May 10, 2015
Messages
322
Office Version
  1. 2021
Platform
  1. Windows
Hi,

I can find sheetnames starting with # using
If ws.Name Like "#*" Then
but
It also finds sheetnames starting with ##

How can I exclude the ## sheets, please ?

Thanks.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
if you're using Like, I suppose this should work:
If ws.Name Like "#*" And Not ws.Name Like "##*" Then

But I would likely prefer to use this:
If Left(ws.Name, 1) = "#" And Left(ws.Name, 2) <> "##" Then
 
Upvote 0
Solution
Many thanks.
Could you explain your reason for the preference, please ?
Regards.
 
Upvote 0
You mentioned this:
I can find sheetnames starting with # using
If ws.Name Like "#*" Then

That's why I said you could use
If ws.Name Like "#*" And Not ws.Name Like "##*" Then

But, as far as I recall, you would have to escape the # character, like this:
If ws.Name Like "[#]*" And Not ws.Name Like "[#][#]*" Then
Because the # symbol is a wildcard for numbers.

So, in order to avoid having conflicts with whatever you have, I suggested the Left method, which does care about wildcards.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,580
Messages
6,160,625
Members
451,659
Latest member
honggamthienha

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