I've looked at many questions with a similar title, but none seem to match my issue.
The snippet of code below is from an initialization routine that I have been running for years with no issue. It only sets variable values and makes no changes to any cells but is called by other routines to set up the Public variables that I need.
Up till now it has always been called when wsPlan
, which is the code name for the sheet, was active. I am currently adding functionality to the workbook on another sheet, where a button will be initiating the subroutine. I am not using the button yet, only testing starting with that sheet active. When I call this routine with this other sheet active I get the 1004
error on the Set StatusFilterIndicator
line but not on the Set SpecViewIndicator
line.
The Cells
row and column numbers were originally variables so I changed them to their values to check if that was an issue but no change. I also rebooted just in case, but no go. However, if I activate wsPlan
before calling the routine there is no error. Right now, that is my workaround but I don't like to leave it that way.
The only difference between the two lines is the use of Range
, because that is two cells. I can think of no reason that should make a difference and this runs perfectly fine when wsPlan
is active. What am I missing?
Public Sub TableInfo
Public SpecViewIndicator As Range
Public StatusFilterIndicator As Range
.
.
.
Set SpecViewIndicator = wsPlan.Cells(1, 22)
Set StatusFilterIndicator = wsPlan.Range(Cells(1, 25), Cells(2, 25))