I just need to activate a certain worksheet. I have a string variable that keeps the name of the worksheet.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With