Return to first worksheet


Posted by Adrae on December 12, 2001 7:10 AM

In my macro, how do I tell excel to activate the first worksheet without knowing the name? Thanks



Posted by Rick E on December 12, 2001 7:47 AM

Well, I assume if you were on the first worksheet to start with, because you now want to return, put the sheet name in a variable and then use that variable to go back to that sheet, see code below"

Sub tester()
' put Sheet name in a variable
sName = ActiveSheet.Name
'
' your code here
'
' Return to the Sheet using the variable
Sheets(sName).Select
'
End Sub

The 'Sheets' object can use an index, Sheets(1); a name, Sheets("Sheet1"); or a variable.

Sheets(1) is the first sheet in the workbook unless they are moved around.

Does that help you? Rick E