how to name a range with vba?

  • Thread starter Thread starter Britt
  • Start date Start date
B

Britt

Hi,

I want to name a range of cells with vba.
I tried: range("b5:b25).name="myname"

but this gives an error.

Thanks
Britt
 
Hi

you need to Set a range
try

Private Sub CommandButton1_Click()
Dim myname As Range
Set myname = Range("b5:b25")
myname.Select
End Sub

S
 
ActiveSheet.Names.Add Name:="MyName", RefersTo:="=$B$5:$B$25"
 
Sub NameRange()
Range("B5:B25").Select
ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=Sheet1!R5C2:R25C2"
End Sub


Vaya con Dios,
Chuck, CABGx3
 
Thanks to all ..

CLR said:
Sub NameRange()
Range("B5:B25").Select
ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=Sheet1!R5C2:R25C2"
End Sub


Vaya con Dios,
Chuck, CABGx3
 
You missed a double quote:

range("b5:b25).name="myname"
should be
range("b5:b25").name="myname"
 

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

Back
Top