VBA to Create Range Names from references

Yoepy

New Member
Joined
Feb 22, 2015
Messages
44
Hello, I hope someone can help.
I need some VBA to create 3 Range names based on column references. My problem is that there may be 100's so I would prefer not to do it manually.

I can create the references based on the columns, so column B would be as follows:

What is the code to look at the cell reference that contains the range name "EVENT1" and give it the reference $A$3:$B$23.

The Name "EVENT1" is in cell B26 and reference $A$3:$B$23 is in B30 (if that makes any difference).

Don't worry about a loop to do it multiple times.
[TABLE="width: 287"]
<tbody>[TR]
[TD]Range name 1
[/TD]
[TD]EVENT1
[/TD]
[/TR]
[TR]
[TD]Range name 2
[/TD]
[TD]EVENT1LessByes
[/TD]
[/TR]
[TR]
[TD]Range name 3
[/TD]
[TD]EVENT1Names
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Range1 Reference
[/TD]
[TD]$A$3:$B$23
[/TD]
[/TR]
[TR]
[TD]Range2 Reference
[/TD]
[TD]$A$4:$B$23
[/TD]
[/TR]
[TR]
[TD]Range3 Reference
[/TD]
[TD]$B$3:$B$23
[/TD]
[/TR]
[TR]
[TD]

[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thank you
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
It is not clear to me where your second and third names and ranges are so here is some code that will create a named range using the B26 and B30
Code:
Sub test()
   Dim ref2 As Range
   
    Nme = Range("B26")
    ref = Range("B30")
    wksnme = ActiveSheet.Name
    Set ref2 = Range(wksnme & "!" & ref)
    ActiveWorkbook.Names.Add Name:=Nme, RefersTo:=ref2


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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