Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default slow macro help

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default slow macro help

Try this

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Mike

"DPingger" wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default slow macro help

Maybe turn off calculation and screen updating before you run your code?

With Application
.Calculation = xlManual
.ScreenUpdating = False
' your code
.ScreenUpdating = True
.Calculation = xlAutomatic
End With

--

Regards,
Nigel




"DPingger" wrote in message
...
I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default slow macro help

How about recording a macro when you select that range
Edit|Replace
what: 0
with: (leave blank)
replace all

Make sure you're looking at entire contents, too.

DPingger wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default slow macro help

Mike, Nigel, and Dave are all correct with turning off screen updating.

That can produce a substantial increase in calculation time. Especially if
you are using a general code to evaluate a significantly large range (or even
an entire sheet).

I wrote a macro to erase all carriage returns, trim out extra spaces, then
resize all columns to auto fit their widest cell entry. The idea was to
clean up financial reports from various companies into a "clean format" so
other macros or worksheet functions worked as expected. Originally I didn't
have screen updating turned off and the macro could take several minutes to
run, added one line of code and presto...down to around 10 seconds. This
various of course but the idea is the same.

"DPingger" wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default slow macro help

I am not sure that Dave Peterson suggested turning off screen updating, what
he did suggest is to use search and replace, a good idea in my view rather
than using code to trawl through cell by cell.

I have not done any tests as to which is faster but I suspect the internal
Excel code is going to be faster?

--

Regards,
Nigel




"Evan Johnson" <Evan
wrote in message
...
Mike, Nigel, and Dave are all correct with turning off screen updating.

That can produce a substantial increase in calculation time. Especially
if
you are using a general code to evaluate a significantly large range (or
even
an entire sheet).

I wrote a macro to erase all carriage returns, trim out extra spaces, then
resize all columns to auto fit their widest cell entry. The idea was to
clean up financial reports from various companies into a "clean format" so
other macros or worksheet functions worked as expected. Originally I
didn't
have screen updating turned off and the macro could take several minutes
to
run, added one line of code and presto...down to around 10 seconds. This
various of course but the idea is the same.

"DPingger" wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default slow macro help

Nigel,

My bad...you caught me. I read through the post rather quickly and I when I
saw the screen updating reference I just wanted to quickly add to the point.
Thanks for keeping me in check.

I just wanted to emphasize the ease and use of that particular code.

I also haven't tried the turning off calculation bit, but I will definately
try adding that in my own work. I've had some projects effectively lock up a
computer from massive and multiple vlookups and it would very helpful to turn
them off, perform some formatting, then turn them back on. Thanks for the tip
"Nigel" wrote:

I am not sure that Dave Peterson suggested turning off screen updating, what
he did suggest is to use search and replace, a good idea in my view rather
than using code to trawl through cell by cell.

I have not done any tests as to which is faster but I suspect the internal
Excel code is going to be faster?

--

Regards,
Nigel




"Evan Johnson" <Evan
wrote in message
...
Mike, Nigel, and Dave are all correct with turning off screen updating.

That can produce a substantial increase in calculation time. Especially
if
you are using a general code to evaluate a significantly large range (or
even
an entire sheet).

I wrote a macro to erase all carriage returns, trim out extra spaces, then
resize all columns to auto fit their widest cell entry. The idea was to
clean up financial reports from various companies into a "clean format" so
other macros or worksheet functions worked as expected. Originally I
didn't
have screen updating turned off and the macro could take several minutes
to
run, added one line of code and presto...down to around 10 seconds. This
various of course but the idea is the same.

"DPingger" wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default slow macro help

Mike, Nigel, Dave and Evan.

Thank you all. Worked like a charm.

You guys are sanity savers.

DPingger

"Evan Johnson" wrote:

Mike, Nigel, and Dave are all correct with turning off screen updating.

That can produce a substantial increase in calculation time. Especially if
you are using a general code to evaluate a significantly large range (or even
an entire sheet).

I wrote a macro to erase all carriage returns, trim out extra spaces, then
resize all columns to auto fit their widest cell entry. The idea was to
clean up financial reports from various companies into a "clean format" so
other macros or worksheet functions worked as expected. Originally I didn't
have screen updating turned off and the macro could take several minutes to
run, added one line of code and presto...down to around 10 seconds. This
various of course but the idea is the same.

"DPingger" wrote:

I am using the following to clear out 0 entries:

Dim cl As Range, myRange As Range
Set myRange = Range("A2:BV2348")
For Each cl In myRange.Cells
If cl.Value = 0 Then cl.ClearContents
Next cl

Is there a way to make this faster or a different approach?
This is taking more than 45 minutes, I don't know why.

TIA

DPingger

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
Slow Macro JRK Excel Programming 7 February 6th 09 01:44 AM
Help with slow Macro Dooza Excel Programming 15 October 30th 08 02:26 PM
slow macro John_A[_2_] Excel Programming 3 March 6th 07 06:36 PM
Macro help, very slow Scott Marcus Excel Programming 0 November 8th 06 05:39 PM
Slow macro alf bryn Excel Programming 5 August 5th 05 12:27 AM


All times are GMT +1. The time now is 07:08 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"