I have an Excel macro that uses Cells(r,c) references extensively, because the layout of the spreadsheet is highly variable. At some point, I need to sort the data, and the columns to be used as sort keys are determined when the macro runs.
The following syntax (from a recorded macro) works fine: Key1:=Range("A2").
With this syntax, the sort appears to do nothing: Key1:=Range(Cells(2,1)).
For most other purposes, Range("A2") and Range(Cells(2,1)) are interchangeable. But apparently not for SORT.
Ultimately, I need the sort key to be dynamic: Key1:=Range(Cells(2, iDocNum)), where iDocNum is a column number.
What am I missing?