Name a Dynamic used range that refreshes when new data is added

Martin sherk

Board Regular
Joined
Sep 11, 2022
Messages
94
Office Version
  1. 365
  2. 2016
I am trying to create a name called "MyData" for a used range in sheet 1, that used range changes a lot due to users adding new rows and columns or even if they delete data in that sheet and add new data .. i want the VBA code to be able to name that new range or data automatically to "MyData" no matter what.

How can I do that, I literally tried everything it either leads to an error message or I have to manually run the code every time, it's really driving me crazy.

My data is in sheet 1 is dynamic and it starts from cell A1.

i really appreciate if anyone can help me with that.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You could use a LAMBDA function instead of VBA.
I posted this LAMBDA function a while back (see this post for the corrected formula!). What I created it for is data that an Add-in can retrieve in a 2 column format - Date and Value. However it is dynamic depending on date, frequency (monthly, etc.) and other factors that change how many columns of data. I call the function _FredRange. It automatically determines how many rows of data there are, and then creates a 2 column array of that many rows with the data in those rows and columns. The only required parameter is the top left cell of the 2 column array. More columns can be optionally specified.
So you end up with a cell with a formula like this:
Excel Formula:
=_FredRange(A2)
Say that formula is in cell D2. You can now create a Named Range (let's call it Fred) by specifying the formula
Excel Formula:
=Sheet7!$D$2#
as the Refers to part of the range. That will give you that dynamic 2 column array, but then simply use
Excel Formula:
=INDEX(Fred,,1)
for the named range FredDt for the first column, and
Excel Formula:
=INDEX(Fred,,2)
for the named range FredVal. (That's what I use for this particular data.
You now have access to three Range Names that refer to data that can dynamically grow or shrink as the data changes.
The LAMBDA function is easily used in any workbook using the Advanced Formula Environment add-in, or through an easy to record Macro in your Personal Workbook.
See what you think about that.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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