Excel 2019
Hi all, wondering if anyone has any preferences or recommendations on dynamic column and row references in Excel VBA? Each time I move a column, my rigid Range references ie "A1" break.
This is a real basic, structural thing that I want to solve with the least computation while I re-write a whole bunch of macros in my workbook that I've been building for 5 years.
Some recommended putting headers at the top of columns and looping through a search in VBA for the headers to return a column number.
I thought if I made each column header a named range, it would be faster for Excel to get the column number by Range("namedRange1").Column. And the same for Row.
That works fine. Please comment if that's not an ideal method computationally.
My new challenge is what syntax to use in combining Range and Cells, if for instance I want to construct a new Range across several cells derived from several different named range's returned column and row numbers.
So if,
namedRange1 column = A
namedRange2 row = 5
namedRange3 column = C
namedRange4 row = 10
desiredRange = Range(Cells(Range("namedRange1").column,Range("namedRange2".row)),Cells("namedRange3").column,Range("namedRange4".row))
So I can wind up with something akin to
desiredRange = Range("a5:c10")
Or is there a way to construct a kind of compound Cells() reference which would be more ideal?
Somehow I'm having a hard time finding the right reference materials online to help me understand this, and I know it's must be very basic, thanks in advance!
Best, Frank
Bookmarks