0
votes

I noticed an interesting problem while trying to debug a VBA routine that sorts the list of worksheets in a range and then redraws the border around that range.

The range containing is defined in Name Manager with the formula as shown below

=Tables!$L$2:$L$22

The problem that is occurring is that while doing the sheet name work, sometimes cells are deleted and sometimes cells are inserted. This CHANGES the cell address values in the named range. So if I deleted two cells and inserted one cell, the formula changes to

=Tables!$L$2:$L$21

And if I happen to insert into the first cell (L2), then the formula changes to

=Tables!$L$3:$L$22

I'm certain that problem can be solved using the header range name and offsetting by one, but I'm not sure how to do that in the formula for a named range as I've tried numerous ways and can't get it right. But I also need the ending range address to be static.

Any help appreciated.

2
remove the $'s .=Tables!L2:L22Nathan_Sav

2 Answers

0
votes

One thing to try is to use:

=Indirect("Tables!$L$2:$L$22")

rather than

=Tables!$L$2:$L$22

It is an acceptable Name, but I am not sure you will get the same functionality.

0
votes

Found a better way than the comment using the static header range. You simply define the whole range using the offset function from the header.

=OFFSET(AllSheetsHeader,1,0,21,1)

Where the 1,0,21,1 are 1 row offset from header, 0 column offset, 21 is row height, and 1 is just that one column