Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Why can't name the range?

I try to name a range as follows:

dim rng as Range, v as String
set rng = LookupSomeRange( v ) 'where LookupSomeRange is a function,
returns range

'now name it, bur has run-time error '1004', the name is not valid

ActiveSheet.Names.add Name:= v, RefersToR1C1="""=" & ActiveSheet.Name
& "!" & v & """", Visible:=True

' i am sure the value of v is unique, there is no name conflict

What went wrong?

-PD

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Why can't name the range?

There was a typo

'now name it, bur has run-time error '1004', the name is not valid

ActiveSheet.Names.add Name:= v, RefersToR1C1="""=" & ActiveSheet.Name
& "!" & v & """", Visible:=True



with ActiveSheet
.Names.add Name:=v, RefersToR1C1="""=" & .Name & "!" &
rng.AddressLocal & """", Visible=True
end with

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Why can't name the range?

I also tried: rng.Name = v or rng.Name.Name = v; neither worked out.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Why can't name the range?

with rng
.name = "'" & .parent.name & "'!" & v
end with

The apostrophes may be required depending on the worksheet name.

And if this doesn't work, what does V hold?

(Even if v is used before, your code won't mind--it'll just reuse it.)

PerlDev wrote:

I try to name a range as follows:

dim rng as Range, v as String
set rng = LookupSomeRange( v ) 'where LookupSomeRange is a function,
returns range

'now name it, bur has run-time error '1004', the name is not valid

ActiveSheet.Names.add Name:= v, RefersToR1C1="""=" & ActiveSheet.Name
& "!" & v & """", Visible:=True

' i am sure the value of v is unique, there is no name conflict

What went wrong?

-PD


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Why can't name the range?

Thanks for your quick response, Dave. It still doesn't work.

dim c as variant, v as String
For each c In Range("A2:A10")
v = c.value
..
with rng
.Name = "'" & .Parent.Name & "'!" & v ' still have Run-time
error '1004', that name is not valid; where v is "ABC-DEF"
end rng
next c
Dave Peterson wrote:
with rng
.name = "'" & .parent.name & "'!" & v
end with




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Why can't name the range?

Figured out: the name couldn't have "-" in it!

PerlDev wrote:
Thanks for your quick response, Dave. It still doesn't work.

dim c as variant, v as String
For each c In Range("A2:A10")
v = c.value
..
with rng
.Name = "'" & .Parent.Name & "'!" & v ' still have Run-time
error '1004', that name is not valid; where v is "ABC-DEF"
end rng
next c
Dave Peterson wrote:
with rng
.name = "'" & .parent.name & "'!" & v
end with


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Why can't name the range?

Yep. Your name is invalid. ABC-DEF can't be used.

dim c as Range
dim v as String
For each c In Range("A2:A10")
v = c.value
v = application.substitute(v,"-","_")
with c
.Name = "'" & .Parent.Name & "'!" & v
end with
next c

And the cell with ABC-DEF will be named ABC_DEF.

And it's "end with" not "End Rng"

And you want to use the same range variable (c, not rng).

And there are lots of other invalid names, too--not just those with hypens.

You'll want to be careful.

PerlDev wrote:

Thanks for your quick response, Dave. It still doesn't work.

dim c as variant, v as String
For each c In Range("A2:A10")
v = c.value
..
with rng
.Name = "'" & .Parent.Name & "'!" & v ' still have Run-time
error '1004', that name is not valid; where v is "ABC-DEF"
end rng
next c
Dave Peterson wrote:
with rng
.name = "'" & .parent.name & "'!" & v
end with


--

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
self-sizing adv.filter criteria range BorisS Excel Discussion (Misc queries) 3 September 24th 06 01:30 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Wrap Text Across Columns & Rows Michael Excel Dude Excel Discussion (Misc queries) 1 September 4th 06 02:14 AM
Duplicate Range Names by worksheet FlaAl Excel Discussion (Misc queries) 0 May 24th 06 05:14 PM
Help with using range names in sum function soteman2005 Excel Worksheet Functions 2 November 28th 05 04:43 PM


All times are GMT +1. The time now is 04:38 PM.

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

About Us

"It's about Microsoft Excel"