Naming cells and referencing in VBA

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Hi everybody,

If I apply a name to cells in a worksheet, and use these names as variables in VB code, do the names follow the cells when changes are made to the worksheet, or are they fixed? If they move, how can they be fixed to point to a certain location, irrespectice to cut/paste operations on the worksheet?

Many thanks,

vcoder
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
1) Names of named ranges will move with the cells if they are cut/pasted - if the ENTIRE NAMED RANGE is moved all at once...not if you cut out a row here, column there. You will however, change the dimension of the range if you cut a row out and so on. This is easily verified with a few tests.

2) Inserting Rows/Cutting Rows/Moving Rows will change references for named Range (even if not rows in the range itself, and even if absolute references are used. Same for columns. Normally this is desireable behavior.

3) You can use the INDIRECT function in Excel to be sure cell references aren't changing ... not sure if you can use these with names.

4) If you don't want the names to move or change, why not just use absolute cell references? Why use names? I suspect that in VBA the use of cell references will not be altered by cut and paste routines - Range("$A$1") is Range("$A$1") regardless of what you do.

HTH
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,088
Messages
5,768,034
Members
425,450
Latest member
JohnBrooksBiddle

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
Top