Wildcard characters inside a worksheet title in VBA

crockwell

New Member
Joined
Jun 28, 2011
Messages
3
I've tried searching for this, but I can't seem to find what I"m looking for...

I'm writing some VBA code where I reference different worksheets. Now, I need to be able to use a wildcard in the worksheet name. Does anyone know if this is possible?

For instance, I need to be able to call up the worksheet "0000-1" in one workbook and then use the same code for a different workbook to call up "0000-2"...etc.

I'd like to call it using...
Sheets("0000-#).Select

Excel doesn't like the #, the * or the ? wildcards.

Any help would be greatly appreciated. Thanks!

Christina
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this. It's pretty basic, but I made three sheets, titled "Temp", "0000-1" and "0000-2". I entered a value in A1 on the Temp sheet and ran my macro, it then passed that value in to the string for my Sheets() section below so the code would switch to the right sheet. The syntax should be easily modified for what you're looking to do.

Hope that helps.

Code:
Sub SheetWildcard()
    Sheets("0000-" & Sheets("Temp").Range("A1").Value).Select
End Sub
 
Upvote 0
Hi crockwell,

Maybe the following example macro may help in some way.

Code:
Sub Select_Sheet()
Dim Sh As Worksheet

For Each Sh In Worksheets
    If Sh.Name Like "0000-[0-9]" Then
        Sheets(Sh.Name).Select
    End If
Next
End Sub
If the names are of the form "0000-#" you can use as above "0000-[0-9]" and if the names could have
one or more than one number like this "0000-##", you can use "0000-[0-9]*" as Regular Expression.

Hope this helps.

Regards.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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