Using wildcard in VBA

akima

New Member
Joined
Mar 4, 2016
Messages
8
I want to use the * wildcard in my VBA formula below


For Each ws In WorksheetsIf ws.Name Like Worksheets("CtrlPnl").Range("*G2").Value
Then
ws.Visible = True

however keep getting Run-time Error '1004'

Please help
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Can you explain exactly what you are trying to do here?
It is hard to guess what that might be from faulty VBA code.
 
Upvote 0
I have a value in Cell G2 in a worksheet called CtrlPnl. The value is 26.12 and I want to search the workbook for any sheet name containing 26.12 e.g. Handover.26.12 or WrkLoad.26.12 and then unhide the sheet.
 
Last edited:
Upvote 0
Add the wildcard(s) to the value from the cell.
Code:
For Each ws In WorksheetsIf ws.Name Like "*" & Worksheets("CtrlPnl").Range("G2").Value & "*"
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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