9tanstaafl9
Well-known Member
- Joined
- Mar 23, 2008
- Messages
- 535
How would I assign an unknown sheetname to a variable so that I can go back to the worksheet again in my macro when I don't know what the name of the sheet will be (the sheet is being added during the macro?)
I was trying to do someting like this, but I keep getting a Runtime Error 9 subscript out of range, so I assume I'm making some sort of operator error... I'm really bad with variables, so I may have missed someting obvious.
'it craps out on the worksheets("myshet"... line
all i'm really trying to do is get back to the newly added sheet, which was added with this line of code earlier in the macro:
I was trying to do someting like this, but I keep getting a Runtime Error 9 subscript out of range, so I assume I'm making some sort of operator error... I'm really bad with variables, so I may have missed someting obvious.
Code:
Dim MySheet As String
MySheet = ActiveSheet.Name
Range("Snapshot3").Select
Application.Goto Reference:="Snapshot3"
Selection.SpecialCells(xlCellTypeVisible).Copy
Worksheets("MySheet").Range("p1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Worksheets("MySheet").Range("P1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'it craps out on the worksheets("myshet"... line
all i'm really trying to do is get back to the newly added sheet, which was added with this line of code earlier in the macro:
Code:
Application.Goto Reference:="Snapshot1"
Selection.SpecialCells(xlCellTypeVisible).Copy
ActiveWorkbook.Worksheets.Add After:=ActiveSheet