Having a Named range Name in a Variable

thesimile

New Member
Joined
Feb 27, 2020
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi Gurus,
I'm looking to check if there is a way we can have an excel variable contain the string value of a named range. For Ex
Defined Name "NameRange" points to cell C1 in excel.
I'm looking for a VBA code like

Dim L_Var As String
L_Var = "NameRange"
Msgbox [L_Var].Value.

I would have option to change L_Var dynamically .
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You don't need a VBA variable. You can just do:
VBA Code:
MsgBox Range("NameRange").Value

Of course, you could set it equal to a variable, i.e.
VBA Code:
Dim L_Var as String
L_Var = Range("NameRange").Value
MsgBox L_Var
Note that this will only work for named ranges that are exactly one cell. If a named range contains more than one cell, you will get errors.
 
Upvote 0
Hi Joe,
VBA Code:
L_Var = Range("NameRange").Value
will return the value in the cell named "NameRange". What I am trying is to, get the value of the value of the named range. The value of named range is dynamically from a variable
 
Upvote 0
Are you saying that your named range contains the cell address of the cell you really want the value from?
For example, in the named range "NameRange", it has a cell value of C1, and C1 is really the cell you want the value from?

If not, then I have no idea what you are talking about, and it would be best for your to fully walk us through an actual examples of that is in the cells, and what you want.
 
Upvote 0
I was able to accomplish this by the below code
Code:
Qst_Range ="Region1"
Set Qst_Name = Range(Names(Qst_Range))

By this , I will be able to change Named range dynamically based on Cell value
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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