named ranges in a For Loop

R

ronnie_knight

I have named ranges in a worksheet (ques1, ques2,etc.). I need a loop
to clear the contents of these ranges, something like:

For i = 1 To 60
Range("ques & i").Select
Selection.ClearContents
Next i

Any suggestions on how to make this work?
 
G

Gary Keramidas

i think jim gave you a suggestion in your original post 2 days ago. did you
try it?
 
C

Chip Pearson

Try

For i = 1 To 60
Range("ques" & i ).ClearContents
Next i


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Guest

TRY,

Dim n As Name
For Each n In ThisWorkbook.Names
If Left(n.Name, 4) = "ques" Then
Range(n).ClearContents
End If
Next
 
R

ronnie_knight

I'M SORRY! I had forgotton I had already posted this. Jim's solution
gives a Method 'Range' of object '_Global' failed. Chip's solution is
almost the same as Jim's. Gary's earlier solution works wonderfully:

Sub Clear_rnge()
For Each nm In ThisWorkbook.Names
Range(nm).ClearContents
Next
End Sub

Please accept my appologies for double posting and thanks for the help.
 
C

Chip Pearson

Sub Clear_rnge()
For Each nm In ThisWorkbook.Names
Range(nm).ClearContents
Next
End Sub

This will clear the contents of ALL names, not just those
beginning with "ques", as the original poster wanted.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Top