Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Clearing all values in range that aren't formulas

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Clearing all values in range that aren't formulas


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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Clearing all values in range that aren't formulas

Bard, one way,
Range("myrange").SpecialCells(xlConstants).ClearCo ntents

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Clearing all values in range that aren't formulas

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).ClearCo ntents

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Clearing all values in range that aren't formulas

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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Clearing all values in range that aren't formulas

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" wrote in message
ups.com...
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).ClearCo ntents

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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Clearing all values in range that aren't formulas

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" wrote in message
...
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" wrote in message
ups.com...
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).ClearCo ntents

--
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" wrote in
message
...
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
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
Clearing cells without clearing formulas marsjune68 Excel Discussion (Misc queries) 2 April 10th 09 07:39 PM
Clear a worksheet without clearing formulas? doodah Excel Discussion (Misc queries) 5 January 23rd 07 06:45 PM
clear the values, but not the formulas in a range aidy Excel Programming 3 October 7th 05 08:08 PM
Select range -- convert formulas to values Johnny[_9_] Excel Programming 3 June 21st 05 03:40 PM
Clearing Contents but not Formulas Louise Excel Worksheet Functions 6 January 27th 05 05:04 PM


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"