Naming a Range read Name from String Variable

radames.rios

New Member
Joined
Nov 30, 2012
Messages
11
Hi people! I'm fairly new to VBA and I'll appreciate your help on this.

I have an argument in which I'm defining a named range, the argument is as follows:

ActiveSheet.Names.Add Name:="JanMax", RefersTo:=ActiveSheet.Range(max)

In this line, I'm creating a range with the name "JanMax" and it refers to a range contained in the variable max (in the form A6:A12 for example). This argument works just fine.

However, instead of naming the name writing a string, I would like to write the string in a variable and put the variable in the argument. For example:

Dim rangename as string
rangename = "JanMax"
ActiveSheet.Names.Add Name:=rangename, RefersTo:=ActiveSheet.Range(max)

Any idea on how can I do this?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Did you try what you posted?
 
Upvote 0

Forum statistics

Threads
1,223,779
Messages
6,174,492
Members
452,567
Latest member
ONEIL290

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