Named range changes after columns inserted, how to fix?

kruuth

New Member
Joined
Sep 1, 2009
Messages
35
Is there a way to "lock" a range? I have a range of values defined as A:G on a sheet. However I have some VBA code that inserts a few columns into that sheet. After that happens the range gets altered to something like H:K. Is it possible to lock this? If not, what is the VBA code to change the range of values for a pre-defined range?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You could change it to its original range within the column insertion code.
Code:
Range("C1:E10").Name = "MyRng"
 
Upvote 0
How would I do this later? It looks like I might have to fix a multitude of ranges on different sheets.
 
Upvote 0
You could place it in the worksheet "Activate" event for each sheet, but if
if the sheet was open and you added the columns , the range would change and not be reinstated.
I don't know your exact circumstance but, I would have thought that if you did all the renaming as you added the columns it would be best.
You would need a list a the bottom of you code like this:-
Code:
Sheets("Sheet10").Range("C1:E10").Name = "MyRng"
Sheets("Sheet15").Range("A1:C5").Name = "ShtRng"
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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