VBA to define named ranges

byrdamy

New Member
Joined
Jun 29, 2007
Messages
15
I am looking to create vba that will define named ranges automatically. I would like to create a worksheet with columns that have the information needed to define the ranges,example: one column would have the desired name of the range, another column would have cell reference that I want the range to refer to

Range Name Refers to
RMEX DET AX1:AX25
RMAP DET Ay1:Ay25


I would then like to add this macro to the workbooks along with the required worksheet and run the macro, to create the named ranges automatically.

I rolled out a report to users they made it specific for their site and now I need to change something that would otherwise require them to have to reenter a ton of information. thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Something like this perhaps, although you can't have spaces in named ranges, so my code changes the spaces to underscores:

Code:
Sub TEST()
Dim c As Range
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    ThisWorkbook.Names.Add Replace(c, " ", "_"), "'" & ActiveSheet.Name & "'!" & c.Offset(, 1)
Next
End Sub
 
Upvote 0
I'd assign the name with the .Name property of a range rather than the .Add method.
Code:
Range("AX1:AX25").Name = "RMEX_DET"

No matter which technique for assigning the name, my biggest concern would be that both the name and the address that the user entered was legal.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

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