In an Exel Macro how do you references worksheets other than the current active worksheet without changing the current worksheet?
In an Exel Macro how do you references worksheets other than the current active worksheet without changing the current worksheet?
Do you mean the old Excel Macros or VBA? If you mean VBA then you need to use the Sheets object so the following gets the value from cell A1 no matter which sheet you are in:
Sub AccessSheet()
' The value in the brackets is referencing which sheet you are trying to access, either a number or
' the actual name of the sheet
MsgBox ActiveWorkbook.Sheets(2).Range("A1").Value
' Accessing sheet by name
MsgBox ActiveWorkbook.Sheets("Sheet2").Range("A1").Value
End Sub
Using a variable is another way:
[vba]
Sub ReferenceThat()
Dim mySht As Worksheet
Set mySht = Sheets("Sheet2")
Set mySht = Sheets(2)
Set mySht = Sheet2
End Sub[/vba] By the way, all 3 lines above refer to the same sheet.
Thanks for the Help.