Generating Named Ranges from 2 text columns (Name and Refers To:)

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
I have a list of 200+ names that I want to turn into defined Named Ranges. They're in 2 simple text columns as shown in the image below. Is there code I can run that will generate these named ranges (the "!DBL" obv refers to a sheet named DBL that already exists in the file)?

EDIT: FWIW, I want them all scoped to the entire Workbook; just wanted to add that detail since I see it's the only other field / variable in Excel's "New Name" dialog box.

losW0QR.jpg
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This one works for me, but you might want to adjust it for your needs:

Code:
Sub CreatingNamedRanges()

    Dim dblWs As Worksheet
    Dim x As Long, LastRow As Long
    
    Set dblWs = ThisWorkbook.Worksheets("DBL")
    
    LastRow = dblWs.Range("A" & Rows.Count).End(xlUp).Row
    
    For x = 2 To LastRow
    
        Names.Add _
            Name:=dblWs.Range("A" & x).Value, _
            RefersTo:="=" & dblWs.Range("B" & x).Value
    
    Next x
    

End Sub
 
Last edited:
Upvote 0
Another option
Code:
Sub d0rian()
   Dim Cl As Range
   With Sheets("[COLOR=#ff0000]List[/COLOR]")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Range(Cl.Offset(, 1)).Name = Cl
      Next Cl
   End With
End Sub
Change sheet name in red to match the sheet with the ranges & names
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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