Automatic range naming

ElvisSteel

Board Regular
Joined
Mar 23, 2009
Messages
122
Hi,

I have a large workbook in which I need to create loads of range names (never mind why)
The ranges are to be called "Range_001" to "Range_100"
I am trying to write some code to avoid having to type these in manually.
I recorded the process of naming the first 2 ranges as such...
Range_001
Code:
    ActiveCell.Range("A1:A25").Select
    ActiveWorkbook.Names.Add Name:="Range_001", RefersToR1C1:= _
        "='Product Details'!R10C21:R34C21"
Range_002
Code:
    ActiveCell.Range("A1:A25").Select
    ActiveWorkbook.Names.Add Name:="Range_002", RefersToR1C1:= _
        "='Product Details'!R10C27:R34C27"
Then I tried to create a loop around this code as follows...
Code:
For s = 21 To 615 Step 6
    ActiveCell.Range("A1:A25").Select
    ProductID = WorksheetFunction.Text((s - 15) / 6, "000")
    RangeName = "Range_" & ProductID
    ActiveWorkbook.Names.Add Name:=RangeName, RefersToR1C1:= _
        "='Product Composer'!R10C21:R34C321"
    ActiveCell.Offset(0, 6).Range("A1").Select
Next s
End Sub
...but I need to replace the two C21 in the the Names.Add statement with effectively "C" & s - can someone please advise

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try:

Code:
ActiveWorkbook.Names.Add Name:=RangeName, RefersToR1C1:= _
        "='Product Composer'!R10C" & s & ":R34C" & s
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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