Geoffrey Barnard
New Member
- Joined
- Jul 27, 2011
- Messages
- 7
Named Ranges
Re: VBA to define named ranges
Hello All,
I’m using Windows XP, Excel 2003
I want to add Named Ranges from a Sheet list.
I found the following code:
Sub TEST()
‘code by HotPepper Mar 20th, 2009, 01:25 AM
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
I changed it to:
Sub AddNamedRangesFromList()
‘code by HotPepper Mar 20th, 2009, 01:25 AM
Dim c As Range
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
ThisWorkbook.Names.Add Replace(c, " ", "_"), "'" & c.Offset(, 1) & "'!" & c.Offset(, 2) & c.Offset(, 3)
Next
End Sub
Works great except the names are enclosed in quotation marks therefore making the names not work. I have tried to get rid of the quotation marks but I don’t know how. Also when I manually delete the quotation marks in dialog box the names do not appear in the formula bar name box unless I hit the Add button. Thanking you, Geoffrey Barnard
Re: VBA to define named ranges
Hello All,
I’m using Windows XP, Excel 2003
I want to add Named Ranges from a Sheet list.
I found the following code:
Sub TEST()
‘code by HotPepper Mar 20th, 2009, 01:25 AM
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
I changed it to:
Sub AddNamedRangesFromList()
‘code by HotPepper Mar 20th, 2009, 01:25 AM
Dim c As Range
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
ThisWorkbook.Names.Add Replace(c, " ", "_"), "'" & c.Offset(, 1) & "'!" & c.Offset(, 2) & c.Offset(, 3)
Next
End Sub
Works great except the names are enclosed in quotation marks therefore making the names not work. I have tried to get rid of the quotation marks but I don’t know how. Also when I manually delete the quotation marks in dialog box the names do not appear in the formula bar name box unless I hit the Add button. Thanking you, Geoffrey Barnard
Last edited: