How to make a range automatically update when rows/cells are added

poiu

Active Member
Joined
Sep 13, 2011
Messages
384
Hello,

If I have the following range:

Code:
Set output_data_range_part_1 = Sheets("Dates database") _ 
.Range("D1:G10")

please can you tell me how to make this range automatically update if, say, a column is added between columns E and F? e.g. in this case I would want the range to change to:

Code:
Set output_data_range_part_1 = Sheets("Dates database") _ 
.Range("D1:[B]H[/B]10")

Thanks,

Poiu
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Poiu,

If you name the range and refer to it by that name, changes in rows & columns will be tracked automatically.

There is also the "Resize" method if you intend to force the change in code.

Gary
 
Upvote 0
If you name the range and refer to it by that name, changes in rows & columns will be tracked automatically.

Thanks Gary, are you referring to setting up a name range outside of VBA and then calling it within the VBA code?
 
Upvote 0
Hi Gary,

Thanks but I'm a bit confused, please could you tell me if this is the correct way to declare a name range in VBA for my example above?

Sheets("Dates database").Range("D1:G10").Name = "the_name_of_my_name_range"

Thanks a lot,

Poiu
 
Upvote 0
That works for me (XL 2000)

Now if you insert a new row or column that intersects that named range (in VBA or from the Excel GUI) the range will expand and include the new row and/or column.

Gary
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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