I am using a variable to reference the name of a sheet in my workbook. It works in one place, but not in another. I know (KNOW!) that I am missing something simple, but I'm not seeing it. Below are the appropriate lines, copied exactly from my VBA in case there are typos (but the error doesn't happen in compile, only when running).
Please Login or Register to view this content.
What am I missing? I get "Run-time error '1004': Application-defined or object-defined error" when I try to run the debug.print line using the variables. I've checked that Var1 and Var2 are holding the right values, that the cell isn't blank (just in case).
I tried the following, but none of these works, either:
Debug.Print Worksheets(sourcesheet).Cells(Var1, Var2).Value
Debug.Print ThisWorkbook.Worksheets(sourcesheet).Cells(Var1, Var2)
Debug.Print ThisWorkbook.Worksheets(sourcesheet).Cells(Var1, Var2).Value
I thought possibly it could be an issue of the subroutine being placed in the wrong module, but all of my VBA is in one Module (Module1, as I wasn't feeling creative).
None of my cells are protected, so that's not the cause.
Thanks for any help you can give me.
Bookmarks