Named Range

C

C Brehm

Sub NewNamedRange(NR As String)
'Nr is sending a number like 2007
Dim aw As String 'used to name range
Dim aw1 As String 'used for range parameters
aw = "Sales" & NR
aw1 = "=" & "sales " & NR & "!$a$2:$i$2"

ActiveWorkbook.Names.Add Name:=aw, RefersTo:=aw1

End Sub

What am I doing wrong?

In the Immediate window
sales= "sales"
nr= "2007"
aw1 = "=" & "sales " & NR & "!$a$2:$i$2"
?aw1
=sales 2007!$a$2:$i$2

aw1 is correct but the named range becomes this
=sales '2007'!$A$2:$I$2
 
B

Bob Phillips

Try this

Sub NewNamedRange(NR As String)
'Nr is sending a number like 2007
Dim aw As String 'used to name range
Dim aw1 As String 'used for range parameters
aw = "Sales" & NR
aw1 = "=" & "'sales " & NR & "'!$a$2:$i$2"

ActiveWorkbook.Names.Add Name:=aw, RefersTo:=aw1

End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Don Guillett

One way.
Sub makename()
nr = 2007
Sheets("Sales " & nr).Range("a2:i2").Name = "Sales" & nr
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top