Where am I going wrong? Cells reference to a range appears to have stopped working!
PS.... I wrote:
Similarly, if the prefix "Sheets(1)." is necessary because that is not
ActiveSheet, note that Cells(1,1) and Cells(27,11) might refer to a
different worksheet.
To that end, it might also be useful to know what kind of module contains
the code fragment: worksheet object or regular module.
You might get to a worksheet object by right-clicking on a worksheet tab in
Excel and clicking on View Code. You might create a regular module by
clicking on Insert, then Module in VBA.
The difference is: in a worksheet object, Cells(1,1) is equivalent to
Me.Cells(1,1), where Me refers to the worksheet containing the code, not
necessarily ActiveSheet.
In contrast, in a regular module, Cells(1,1) is equivalent to
ActiveSheet.Cells(1,1). This is the case even if the procedure in the
regular module is called from a procedure in a worksheet object.
If you have any doubts, one of the following might be useful for determining
exactly what Cells(1,1) refers to:
MsgBox Cells(1,1).Address(external:=True)
Debug.Print Cells(1,1).Address(external:=True)
The output for the latter can found in the Immediate Window (press ctrl+G).
|