Dynamic named range that can accurately capture both row & column extremes

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
348
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
My goal is to capture the filter criteria using VBA when a user has multiple conditions active across several fields (columns). I've come very close to this, but ultimately there are still tilt scenarios that I can't leave unaddressed.
A basic dynamic named range AFAIK uses something like:

Excel Formula:
=OFFSET($C$2, 0, 0, COUNTA($C$2:$C$), 1)

My intent was to also capture the columns since the first subroutine will need to output data in an 2D array. I replaced the above formula's last argument with a span of columns, then I ran the code that reads the array into a variable, but it always had something wrong with it. Either too short, too long, or not capturing values after blanks, etc. I turned to experimenting on the formula on the spreadsheet, and finally came up with something.
This was my (super-convoluted) formula that produced the correct results on the spreadsheet, but wouldn't take as a DNR.

Excel Formula:
=OFFSET(Internals!$C$2,0,0,COUNTA(Internals!$C$2:$C$23)+COUNTBLANK(INDIRECT(CONCAT("$C$2:",ADDRESS(MATCH(LOOKUP(2,1/(Internals!$C$2:$C$23<>""),Internals!$C$2:$C$23),Internals!C2:C23,0)+1,3)))),MAX(COUNTA(Internals!C2:XFD2),COUNTA(Internals!C3:XFD3),COUNTA(Internals!C4:XFD4),COUNTA(Internals!C5:XFD5),COUNTA(Internals!C6:XFD6),COUNTA(Internals!C7:XFD7),COUNTA(Internals!C8:XFD8),COUNTA(Internals!C9:XFD9),COUNTA(Internals!C10:XFD10),COUNTA(Internals!C11:XFD11),COUNTA(Internals!C12:XFD12),COUNTA(Internals!C13:XFD13),COUNTA(Internals!C14:XFD14),COUNTA(Internals!C15:XFD15),COUNTA(Internals!C16:XFD16),COUNTA(Internals!C17:XFD17),COUNTA(Internals!C18:XFD18),COUNTA(Internals!C19:XFD19),COUNTA(Internals!C20:XFD20),COUNTA(Internals!C21:XFD21),COUNTA(Internals!C22:XFD22),COUNTA(Internals!C23:XFD23)))

Basically, I believe that the hangup is related to the INDIRECT formula being used, so if I could recall a non-volatile way to concatenate two cells into a range, that would probably solve the issue. It will still need to find the last cell in the row (or column for that matter), so that the range's end point is known.

Thanks for clearing any of this up for me.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I am little confused in that you mention using VBA but seem to be only using excel formulas.

Your profile says you have 365 so the below should return the last value in the column.
Excel Formula:
XLOOKUP(TRUE,(NOT(ISBLANK(A:A))),A:A,"Unknown",0,-1)

And this the last row.
Excel Formula:
ROW(XLOOKUP(TRUE,(NOT(ISBLANK(A:A))),A:A,"Unknown",0,-1))
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,935
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top