I just need to activate a certain worksheet. I have a string variable that keeps the name of the worksheet.
Asked
Active
Viewed 7.9e+01k times
64
-
Is it possible to have the top answer accepted (either by @Alex or by a mod)? I would love to see this gone from open questions just to accommodate my OCD ^^ – Marcus Mangelsdorf Jan 28 '21 at 09:51
3 Answers
100
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

Dennis G
- 21,405
- 19
- 96
- 133
-
3`sheetname` can be worksheet index number (so integer). Even if the `Option Base` value is 0, it starts from index 1. – Fatih Mert Doğancan Jan 03 '18 at 04:17
5
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.

Moreno
- 608
- 1
- 9
- 24
0
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.

Daan
- 49
- 3