ransomedbyfire
Board Regular
- Joined
- Mar 9, 2011
- Messages
- 121
I am trying to convert all my sheet references in my code to the format "Sheet1", etc. instead of "Sheets(1)", etc. to avoid getting my sheet numbers mixed up when things change in the spreadsheet.
I wrote a simple piece of code to try to get the syntax right. It worked in the almost empty workbook where I was testing it; but then when I tried to copy it into the spreadsheet I am actually working on, it gave me a "Subscript out of range" error. So, I closed the spreadsheet and went back to my test spreadsheet and re-ran the code, and it didn't work there either.
What's going on here? And how can I make it work every time?
Here is my test code.
I wrote a simple piece of code to try to get the syntax right. It worked in the almost empty workbook where I was testing it; but then when I tried to copy it into the spreadsheet I am actually working on, it gave me a "Subscript out of range" error. So, I closed the spreadsheet and went back to my test spreadsheet and re-ran the code, and it didn't work there either.
What's going on here? And how can I make it work every time?
Here is my test code.
Code:
Sub test2()
For i = 1 To 3
Sheets("Sheet" & i).Select
ActiveSheet.Range("b1") = "Sheet" & i
Next i
End Sub