View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
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