Reputation: 659
I just need to activate a certain worksheet. I have a string variable that keeps the name of the worksheet.
Upvotes: 65
Views: 797177
Reputation: 638
I would recommend you to use worksheet's index instead of using worksheet's name, in this way you can also loop through sheets "dynamically"
for i=1 to thisworkbook.sheets.count
sheets(i).activate
'You can add more code
with activesheet
'Code...
end with
next i
It will also, improve performance.
Upvotes: 6
Reputation: 49
An alternative way to (not dynamically) link a text to activate a worksheet without macros is to make the selected string an actual link. You can do this by selecting the cell that contains the text and press CTRL+K then select the option/tab 'Place in this document' and select the tab you want to activate. If you would click the text (that is now a link) the configured sheet will become active/selected.
Upvotes: 0
Reputation: 21778
Would the following Macro help you?
Sub activateSheet(sheetname As String)
'activates sheet of specific name
Worksheets(sheetname).Activate
End Sub
Basically you want to make use of the .Activate function. Or you can use the .Select function like so:
Sub activateSheet(sheetname As String)
'selects sheet of specific name
Sheets(sheetname).Select
End Sub
Upvotes: 101