PC Review


Reply
Thread Tools Rate Thread

clear ranges

 
 
Striker
Guest
Posts: n/a
 
      15th Jul 2009
I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
clear all named ranges. currently I am clearing like this, but it is
getting too long to do with all the ranges. not sure how to assing a range
name to a variable and clear it.

With ActiveSheet

Range("ONE").Select
Selection.ClearContents
Selection.ClearComments

Range("TWO").Select
Selection.ClearContents
Selection.ClearComments

Range("THREE").Select
Selection.ClearContents
Selection.ClearComments
end with

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      15th Jul 2009
Perhaps a sample with actual ranges may be of help in designing a loop

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Striker" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
>clear all named ranges. currently I am clearing like this, but it is
>getting too long to do with all the ranges. not sure how to assing a range
>name to a variable and clear it.
>
> With ActiveSheet
>
> Range("ONE").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("TWO").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("THREE").Select
> Selection.ClearContents
> Selection.ClearComments
> end with


 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      15th Jul 2009
Try something like this:
Sub test()
Dim n As Name
For Each n In ThisWorkbook.Names
Range(n).ClearContents
Range(n).ClearComments
Next n
End Sub

Regards,
Stefi

„Striker” ezt *rta:

> I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
> clear all named ranges. currently I am clearing like this, but it is
> getting too long to do with all the ranges. not sure how to assing a range
> name to a variable and clear it.
>
> With ActiveSheet
>
> Range("ONE").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("TWO").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("THREE").Select
> Selection.ClearContents
> Selection.ClearComments
> end with
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      15th Jul 2009
OR this with no loop and no selections.
with Range("a1:b2,c4:d5,etc")
.ClearContents
.ClearComments
end with

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Striker" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
>clear all named ranges. currently I am clearing like this, but it is
>getting too long to do with all the ranges. not sure how to assing a range
>name to a variable and clear it.
>
> With ActiveSheet
>
> Range("ONE").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("TWO").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("THREE").Select
> Selection.ClearContents
> Selection.ClearComments
> end with


 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      15th Jul 2009
Or with names:
With Range("name1, name2, etc.")

Stefi

„Don Guillett” ezt *rta:

> OR this with no loop and no selections.
> with Range("a1:b2,c4:d5,etc")
> .ClearContents
> .ClearComments
> end with
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "Striker" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
> >clear all named ranges. currently I am clearing like this, but it is
> >getting too long to do with all the ranges. not sure how to assing a range
> >name to a variable and clear it.
> >
> > With ActiveSheet
> >
> > Range("ONE").Select
> > Selection.ClearContents
> > Selection.ClearComments
> >
> > Range("TWO").Select
> > Selection.ClearContents
> > Selection.ClearComments
> >
> > Range("THREE").Select
> > Selection.ClearContents
> > Selection.ClearComments
> > end with

>
>

 
Reply With Quote
 
Striker
Guest
Posts: n/a
 
      15th Jul 2009
OK, this works, I just need to be sure it only happens on the current
worksheet, not workbook.


"Stefi" <(E-Mail Removed)> wrote in message
news:36545525-3FA8-4BD9-AC4B-(E-Mail Removed)...
> Try something like this:
> Sub test()
> Dim n As Name
> For Each n In ThisWorkbook.Names
> Range(n).ClearContents
> Range(n).ClearComments
> Next n
> End Sub
>
> Regards,
> Stefi
>
> "Striker" ezt rta:
>
>> I have about 40 named ranges in a sheet. I need do quickly do a ,loop
>> and
>> clear all named ranges. currently I am clearing like this, but it is
>> getting too long to do with all the ranges. not sure how to assing a
>> range
>> name to a variable and clear it.
>>
>> With ActiveSheet
>>
>> Range("ONE").Select
>> Selection.ClearContents
>> Selection.ClearComments
>>
>> Range("TWO").Select
>> Selection.ClearContents
>> Selection.ClearComments
>>
>> Range("THREE").Select
>> Selection.ClearContents
>> Selection.ClearComments
>> end with
>>
>>



 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      15th Jul 2009
Option Explicit
Sub clearRanges()
clearSheetRanges "sheet2"
End Sub

Sub clearSheetRanges(sh As String)
Dim nm As Name
Dim rng As Range
For Each nm In ThisWorkbook.Names
Set rng = Range(nm)
If UCase(rng.Parent.Name) = UCase(sh) Then
Worksheets(sh).Range(nm).ClearContents
End If
Next
End Sub

"Striker" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> I have about 40 named ranges in a sheet. I need do quickly do a ,loop and
> clear all named ranges. currently I am clearing like this, but it is
> getting too long to do with all the ranges. not sure how to assing a
> range name to a variable and clear it.
>
> With ActiveSheet
>
> Range("ONE").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("TWO").Select
> Selection.ClearContents
> Selection.ClearComments
>
> Range("THREE").Select
> Selection.ClearContents
> Selection.ClearComments
> end with


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear contents on specified ranges Piotr (Peter) Microsoft Excel Programming 3 5th Feb 2010 11:56 AM
Clear Contents of multiple continuous ranges Mlawrence Microsoft Excel Programming 2 28th Feb 2008 09:16 PM
Clear Named Ranges Les Stout Microsoft Excel Programming 3 7th Mar 2007 06:17 PM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Microsoft Excel Programming 0 21st Aug 2006 03:51 PM
clear and remove all ranges and names sophic Microsoft Excel Programming 4 9th Mar 2004 11:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:36 PM.