How to find tabs that have slightly different names with wildcard?

ironny90

Board Regular
Joined
Mar 29, 2022
Messages
72
Office Version
  1. 2010
Platform
  1. Windows
Hi there! I am here again. Now I am trying to find a tab in a worksheet, which might have different names due to formatting inconsistency.

It might be named as 08-22 or 8-22. I used wildcard "*" to replace the zero, but vba says out of range.

Set ff = fso.getfolder(folderpath)
For Each file In ff.Files
Workbooks.Open file

Sheets("*8-22").Copy Before:=Sheets("*8-22")
Sheets("*8-22 (2)").Name = "9-22"

Is this the right way to use wildcard? Sorry if some my errors are quite obvious. Thank you for your help in advance!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You can't use a wildcard like that to find a specific worksheet. Instead, you have to loop through each sheet and use the wildcard with the Like operator and see if the worksheet's name matches:
VBA Code:
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name Like "*8-22" Then
            ws.Copy Before:=ws
            ActiveSheet.Name = "9-22"
        End If
    Next
 
Upvote 0
Solution
That's what I found as well^^ I tried the loop as well but it didn't find anything;) Let me test more. Thank you soooo much!!!
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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