danbrawl93
New Member
- Joined
- Dec 15, 2016
- Messages
- 17
Hello,
I have been using the Like operator in VBA to activate sheets if they have a given start to their name. See example below:
Sheet name = "AI. 1234567"
Identifying start to name = "AI."
The code for this would be as follows:
However, I now have an issue due to a sheet being named in the following format, which is also activated: "MA. Example"
I thought my code above would simply activate sheets beginning, and only beginning, with "AI." with the * providing a wildcard for the rest of the sheet name. Clearly I am mistaken, so could somebody please explain how the * works and why the undesired sheet is being activated? If an alternative can be used to activate sheets with a specific start to its name ("AI." in this case) then please let me know, as this is the desired effect.
Many, many thanks!
Dan
I have been using the Like operator in VBA to activate sheets if they have a given start to their name. See example below:
Sheet name = "AI. 1234567"
Identifying start to name = "AI."
The code for this would be as follows:
Code:
For Each sh In Worksheets
If sh.name Like "AI.*" Then
sh.Activate
' Do stuff
End If
Next sh
However, I now have an issue due to a sheet being named in the following format, which is also activated: "MA. Example"
I thought my code above would simply activate sheets beginning, and only beginning, with "AI." with the * providing a wildcard for the rest of the sheet name. Clearly I am mistaken, so could somebody please explain how the * works and why the undesired sheet is being activated? If an alternative can be used to activate sheets with a specific start to its name ("AI." in this case) then please let me know, as this is the desired effect.
Many, many thanks!
Dan