Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default named ranges in a For Loop

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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default named ranges in a For Loop

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

--


Gary


wrote in message
oups.com...
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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default named ranges in a For Loop

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


wrote in message
oups.com...
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?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default named ranges in a For Loop


TRY,

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

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


" wrote:

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?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default named ranges in a For Loop

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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default named ranges in a For Loop

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



wrote in message
oups.com...
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.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default named ranges in a For Loop

yep, clearly stated in my original post.

--


Gary


"Chip Pearson" wrote in message
...
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



wrote in message
oups.com...
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.





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
Loop thru named range of second sheet Bill Sturdevant[_2_] Excel Programming 3 July 29th 05 07:15 PM
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
loop through all named ranges Bert[_3_] Excel Programming 4 June 19th 04 03:54 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM
Excel VBA - loop columns named AA, AB..etc Tobias[_2_] Excel Programming 3 April 19th 04 01:26 PM


All times are GMT +1. The time now is 10:17 PM.

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"