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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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