Rex said:
The code shown below runs through about 6000 rows
and takes 5 minutes
I was able to duplicate your 5-min runtime by filling A1:Z7000 with =RAND().
While a completely different algorithm might be a good idea, I was able to
reduce that time to about 0.6 sec by applying just a couple simple principles
to your algorithm:
1. Disable certain actions that might occur as each row is hidden.
2. Hide rows from the bottom up, not from the top down.
#1 reduced the runtime to about 1.5 sec. #2 reduced the runtime to about
0.6 sec.
Of course, your times might be different. But I would expect comparable or
better improvement, considering my pervasive use of RAND.
Also note the correction, which I presume is your intention: If-Then-Else
instead of If/If.
The Range.Offset expression could be done a better way. I wrote it that way
to make it easier for you to relate to your original algorithm.
My macro....
Option Explicit
Sub doit()
Dim R As Range, i As Long
'more robust: save the original states in variant
'variables and restore them at the end
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
For i = 6210 To 7 Step -1
Set R = Range("c1").Offset(i - 1, 0)
If R.Value = "0" Then Rows(R.Row).Hidden = True _
Else If R.Value = "" Then Rows(R.Row).Hidden = True
Next
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
----- original message -----