Alternative named range

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
It is safer to refer to worksheet codenames than worksheet names because users can easily change the name of a worksheet but not its codename, so I tend to write:

Code:
wksData.Cells(1, 1).Value = 10

as opposed to:

Code:
Worksheets("Data").Cells(1, 1).Value = 10

Is there something similar for named ranges, ie I prefer NOT to write:

Code:
wksData.Range("SomeName").Value = 10

just in case the named range SomeName has been changed.

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You can set up range variables and set them, just the same as you can with worksheets, i.e.
Code:
Dim rng as Range
Set rng = Range("A1")

wksData.rng.Value = 10
 
Upvote 0
One way to keep your named ranges would be to set their visible property to False.
Code:
ThisWorkbook.Name("myNamedRange").Visible = False
Which removes the named range from the Names manager, so the user can't change them. The user can create a second name for the same range but not remove the hidden name.
(But deleting the cells in the range, making the Name refer to #REF is another issue)
 
Upvote 0
One way to keep your named ranges would be to set their visible property to False.
Code:
ThisWorkbook.Name("myNamedRange").Visible = False
Which removes the named range from the Names manager, so the user can't change them. The user can create a second name for the same range but not remove the hidden name.
(But deleting the cells in the range, making the Name refer to #REF is another issue)


Thanks but I'm in the process of changing some of my named ranges myself!

Like the worksheets example, although I may want to change the worksheets name, the worksheets' codename will remain the same.

So was just wondering if I could do the same for named ranges.
 
Upvote 0
Like the worksheets example, although I may want to change the worksheets name, the worksheets' codename will remain the same.

So was just wondering if I could do the same for named ranges.
Did you see my reply?
I showed you how to create object variables for your range the same as you did for your sheet.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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