Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with variable range names in excel vba

Status
Not open for further replies.

danomaniac

Programmer
Jan 16, 2002
266
US
I'm having trouble referencing range names in my code..

I have several ranges named "range01", "range02", "range03" etc.

I want to clear the contents of all the ranges and this is what I have, and it gives me an error 1004 'Method range of object _worksheet failed"

dim rname as string

For i = 1 to 3
rname = "range0" & i
Range(rname).clearcontents
next

Thanks.



"It's more like it is now, than it ever has been."
 
first of all what's in Range01-03?
have you tried dim them as string?

Everybody is somebodys Nutter.
 
Try this

Range(ActiveWorkbook.Names( rname)).ClearContents

ck1999
 





Hi,

works for me.

Try to quallify the Range object with the Worksheet object.
Code:
   [b]worksheets("YourSheetName").[/b]Range(rname).clearcontents

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Thanks,
Both ways work great. I appreciate it.



"It's more like it is now, than it ever has been."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top