Named Constants w/ VBA

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
95
Hi -

I've created a Name using the 'Name Manager' and called it 'User'. The name is a Named Constant, so it doesn't refer to a range on the spreadsheet. In the 'Refers To' dialog box it has:

="GRC"

When I try to refer to this in VBA, I would expect to get

GRC

but what I'm getting is:

="GRC"

Here is the code I'm using:
Dim sUser as String
sUser = ThisWorkbook.Names("User").RefersTo

Anyone know how to get rid of the equals sign (=) and the quotations ("")?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi

The RefersTo property of the Name object gives you the definition of the object. In this case what you want is what it evaluates to.

Try:

Code:
sUser = Evaluate("user")

or its shorhand

Code:
sUser = [user]
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,645
Members
449,461
Latest member
kokoanutt

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