Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Naming Ranges

I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address


Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Naming Ranges

Forgot to mention, the error is:

Run-time error '1004'"

Thant name is not valid.


Thanks,
Paul

"PCLIVE" wrote in message
...
I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address


Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Naming Ranges

You're trying to name a range 950.

Excel says that the name 950 looks to much like the number 950.

Maybe you can use:

name:="_"&range("a"&r1).value

(prepending an underscore)

=====
Imagine if you wrote
=950*2
and didn't get 1900 back!

PCLIVE wrote:

I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address

Thanks.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Naming Ranges

The error description is the answer!

Regards,
Peter T

PS defined names starting with a numeral are not valid


"PCLIVE" wrote in message
...
Forgot to mention, the error is:

Run-time error '1004'"

Thant name is not valid.


Thanks,
Paul

"PCLIVE" wrote in message
...
I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address


Thanks.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Naming Ranges

Thanks,

I had just figured this out when you responded. However, I had orginally
been using a cobination of letters with numbers and the letters were in
front. I was still getting the error then, so I shortend the name to make
the inquiry simpler. After discovering that the name could not begin with a
number, I then realized that my original problem was caused by a space in
the cell value. Since Excel automatically substitutes spaces with
underscores when you manually create the named range, I did not notice that
this was the happening when trying to apply the same thing via VBA. Anyway,
it's working now.

Thanks,
Paul


"Peter T" <peter_t@discussions wrote in message
...
The error description is the answer!

Regards,
Peter T

PS defined names starting with a numeral are not valid


"PCLIVE" wrote in message
...
Forgot to mention, the error is:

Run-time error '1004'"

Thant name is not valid.


Thanks,
Paul

"PCLIVE" wrote in message
...
I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address


Thanks.









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Naming Ranges

Be careful with names that look too much like addresses, too.

A1 wouldn't work as a range name (while in A1 Reference style).

PCLIVE wrote:

Thanks,

I had just figured this out when you responded. However, I had orginally
been using a cobination of letters with numbers and the letters were in
front. I was still getting the error then, so I shortend the name to make
the inquiry simpler. After discovering that the name could not begin with a
number, I then realized that my original problem was caused by a space in
the cell value. Since Excel automatically substitutes spaces with
underscores when you manually create the named range, I did not notice that
this was the happening when trying to apply the same thing via VBA. Anyway,
it's working now.

Thanks,
Paul

"Peter T" <peter_t@discussions wrote in message
...
The error description is the answer!

Regards,
Peter T

PS defined names starting with a numeral are not valid


"PCLIVE" wrote in message
...
Forgot to mention, the error is:

Run-time error '1004'"

Thant name is not valid.


Thanks,
Paul

"PCLIVE" wrote in message
...
I'm having trouble naming a range with this code.
B1 to D7 is selected.
r1 = 1
A1 = "950"
Why isn't this working?

ActiveWorkbook.Names.Add Name:=Range("A" & r1).Value,
RefersTo:=Selection.Address


Thanks.






--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming ranges Amin Setting up and Configuration of Excel 1 April 25th 10 05:45 PM
naming ranges TechyTemp Excel Worksheet Functions 0 November 29th 06 09:18 PM
Naming Ranges Simon Shaw Excel Discussion (Misc queries) 1 February 15th 05 01:17 AM
Naming Ranges Donna In Denver Excel Discussion (Misc queries) 1 January 28th 05 07:48 AM
naming ranges Alexander Bogomolny Excel Programming 2 July 28th 04 02:27 AM


All times are GMT +1. The time now is 04:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"