PDA

View Full Version : Sleeper: Problem with sheet search



IVY440
08-19-2005, 05:35 AM
Here I am again with a question.
Still the same old project.
So I attach a string to the variable City and another string to the variable Land.
How can I activate the sheet with the name Land - City ?
I tried:
1)
Variable3 = Land & " - " & City
Sheets(Variable3).Activate

2)
Sheets(Land & " - " & City).activate

On Option 1 he gives a "Subscript out of range" error
Option 2 is even impossible due to the " " .
How can I fix this problem?

BlueCactus
08-19-2005, 07:15 AM
'Subscript out of range' is telling you that there is no sheet with that name.

Try sticking in a

Msgbox Land & " - " & City
as the second line to see if you are getting the correct name.

MWE
08-19-2005, 09:27 AM
Here I am again with a question.
Still the same old project.
So I attach a string to the variable City and another string to the variable Land.
How can I activate the sheet with the name Land - City ?
I tried:
1)
Variable3 = Land & " - " & City
Sheets(Variable3).Activate

2)
Sheets(Land & " - " & City).activate

On Option 1 he gives a "Subscript out of range" error
Option 2 is even impossible due to the " " .
How can I fix this problem?
There is nothing fundamentally wrong with the name you are trying to construct for a sheet. Personally, I do not recommend that there be any blanks in any name for anything, but Excel does allow blanks in sheet names. I assume that you have loaded the string variable City and the string variable Land with appropriate text; something like

City = "Miami"
Land = "NoMans"

and are looking for the sheet with name = "NoMans - Miami"

After you try BlueCactus's suggestion; if that does not resolve you problem, loop through all sheets in VBA and display their names. Perhaps there is something amiss that is not obvious when you simply look at them as tabs.