PC Review


Reply
Thread Tools Rate Thread

Clearing all values in range that aren't formulas

 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      18th Oct 2006
I have a range called myRange and I'd like to clear out all values that
aren't formulas. How would I do this programmatically?

Thanks
 
Reply With Quote
 
 
 
 
John Coleman
Guest
Posts: n/a
 
      18th Oct 2006

Sub ClearNonFormulas()
Dim cl As Range, myRange As Range
Set myRange = Range("myRange")
For Each cl In myRange.Cells
If cl.HasFormula = False Then cl.ClearContents
Next cl
End Sub

HTH
-John Coleman

Barb Reinhardt wrote:
> I have a range called myRange and I'd like to clear out all values that
> aren't formulas. How would I do this programmatically?
>
> Thanks


 
Reply With Quote
 
Paul B
Guest
Posts: n/a
 
      18th Oct 2006
Bard, one way,
Range("myrange").SpecialCells(xlConstants).ClearContents

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:588C587C-51CB-4978-9FC2-(E-Mail Removed)...
>I have a range called myRange and I'd like to clear out all values that
> aren't formulas. How would I do this programmatically?
>
> Thanks



 
Reply With Quote
 
John Coleman
Guest
Posts: n/a
 
      18th Oct 2006
You are being modest, you should almost say "the only way". I created a
range with about 200,000 cells and my looping-through-the cells
checking the hasformula property strategy took several minutes but the
shorter code you gave works in about 10 seconds. Pretty nice speed-up!

Thanks for educating me a bit.

-John Coleman

Paul B wrote:
> Bard, one way,
> Range("myrange").SpecialCells(xlConstants).ClearContents
>
> --
> Paul B
> Always backup your data before trying something new
> Please post any response to the newsgroups so others can benefit from it
> Feedback on answers is always appreciated!
> Using Excel 2002 & 2003
>
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:588C587C-51CB-4978-9FC2-(E-Mail Removed)...
> >I have a range called myRange and I'd like to clear out all values that
> > aren't formulas. How would I do this programmatically?
> >
> > Thanks


 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      18th Oct 2006
Thanks. That does exactly what I want.

"John Coleman" wrote:

>
> Sub ClearNonFormulas()
> Dim cl As Range, myRange As Range
> Set myRange = Range("myRange")
> For Each cl In myRange.Cells
> If cl.HasFormula = False Then cl.ClearContents
> Next cl
> End Sub
>
> HTH
> -John Coleman
>
> Barb Reinhardt wrote:
> > I have a range called myRange and I'd like to clear out all values that
> > aren't formulas. How would I do this programmatically?
> >
> > Thanks

>
>

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      19th Oct 2006
It is great, but
Just be aware that if there are more than 8192 separate cells (separate
areas), then this will fail without warning. (it will appear to work but
won't)

http://support.microsoft.com/default...b;en-us;832293
The .SpecialCells(xlCellTypeBlanks) VBA function does not work as expected
in Excel



--
Regards,
Tom Ogilvy


"John Coleman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You are being modest, you should almost say "the only way". I created a
> range with about 200,000 cells and my looping-through-the cells
> checking the hasformula property strategy took several minutes but the
> shorter code you gave works in about 10 seconds. Pretty nice speed-up!
>
> Thanks for educating me a bit.
>
> -John Coleman
>
> Paul B wrote:
>> Bard, one way,
>> Range("myrange").SpecialCells(xlConstants).ClearContents
>>
>> --
>> Paul B
>> Always backup your data before trying something new
>> Please post any response to the newsgroups so others can benefit from it
>> Feedback on answers is always appreciated!
>> Using Excel 2002 & 2003
>>
>> "Barb Reinhardt" <(E-Mail Removed)> wrote in
>> message
>> news:588C587C-51CB-4978-9FC2-(E-Mail Removed)...
>> >I have a range called myRange and I'd like to clear out all values that
>> > aren't formulas. How would I do this programmatically?
>> >
>> > Thanks

>



 
Reply With Quote
 
Paul B
Guest
Posts: n/a
 
      19th Oct 2006
Tom, thanks I did not know about that.

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Tom Ogilvy" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> It is great, but
> Just be aware that if there are more than 8192 separate cells (separate
> areas), then this will fail without warning. (it will appear to work but
> won't)
>
> http://support.microsoft.com/default...b;en-us;832293
> The .SpecialCells(xlCellTypeBlanks) VBA function does not work as expected
> in Excel
>
>
>
> --
> Regards,
> Tom Ogilvy
>
>
> "John Coleman" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> You are being modest, you should almost say "the only way". I created a
>> range with about 200,000 cells and my looping-through-the cells
>> checking the hasformula property strategy took several minutes but the
>> shorter code you gave works in about 10 seconds. Pretty nice speed-up!
>>
>> Thanks for educating me a bit.
>>
>> -John Coleman
>>
>> Paul B wrote:
>>> Bard, one way,
>>> Range("myrange").SpecialCells(xlConstants).ClearContents
>>>
>>> --
>>> Paul B
>>> Always backup your data before trying something new
>>> Please post any response to the newsgroups so others can benefit from it
>>> Feedback on answers is always appreciated!
>>> Using Excel 2002 & 2003
>>>
>>> "Barb Reinhardt" <(E-Mail Removed)> wrote in
>>> message
>>> news:588C587C-51CB-4978-9FC2-(E-Mail Removed)...
>>> >I have a range called myRange and I'd like to clear out all values that
>>> > aren't formulas. How would I do this programmatically?
>>> >
>>> > Thanks

>>

>
>



 
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
clearing values of cells in named range(s) so the cells are empty BRC Microsoft Excel Programming 1 10th Jan 2010 06:54 AM
Clearing Values in a Range under certain conditions =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 2 8th Nov 2006 02:24 PM
HELP - Excel 2003 formulas don't work-as if cell values aren't num =?Utf-8?B?c2lzeXBodXM=?= Microsoft Excel Worksheet Functions 4 1st Jun 2006 07:43 PM
clear the values, but not the formulas in a range aidy Microsoft Excel Programming 3 7th Oct 2005 08:08 PM
Select range -- convert formulas to values Johnny Microsoft Excel Programming 3 21st Jun 2005 03:40 PM


Features
 

Advertising
 

Newsgroups
 


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