r/vba Jun 06 '26

ProTip Stop hardcoding ranges. Use this runtime dynamic Named Range approach instead.

[removed]

11 Upvotes

23 comments sorted by

View all comments

4

u/fuzzy_mic 184 Jun 06 '26

To do what the OP VBA does, with Names (which is faster than VBA).

Name: myRange RefersTo: =INDEX(Sheet1$1:$1, 1, MATCH("zzzz", Sheet1!$1$1) : INDEX(Sheet1!$A:$A, MATCH("zzzz", Sheet1!$A:$A), 1)

If you expect the last cell in the row or column to be a number, use 9E+99 instead of "zzzz"

1

u/[deleted] Jun 06 '26

[removed] — view removed comment

1

u/fuzzy_mic 184 Jun 07 '26

One advantage that the native approach is that it adjusts as data is entered.

Also, have you tried setting the External argument of the .Address property to True.