View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Kieranz[_2_] Kieranz[_2_] is offline
external usenet poster
 
Posts: 55
Default Efficient looping

On Sep 8, 7:09*pm, "Rick Rothstein"
wrote:
I prefer that loop because it only matches cells where something is to
be done. I infer you used For Each for symmetry with other examples.
OTOH, you may have information that your construct takes less time.
I would suspect not - fewer code lines are executed - but have not
measured.


I haven't measured that either, but I suspect whether it is faster or
not may depend on the nature and amount of the data


Assuming your data is constants, not formulas (although I can modify this
for that case), this will probably be one of the fastest methods to hide the
rows for cells with a number 1 in them - and notice, no loops whatsoever....

Sub HideRowsWithOnes()
* With Columns("A")
* * .Replace 1, "=1", xlWhole
* * .SpecialCells(xlCellTypeFormulas).EntireRow.Hidden = True
* * .Replace "=", "", xlPart
* End With
End Sub

Rick Rothstein (MVP - Excel)


Hi Ron, tried the autofilter and works like a charm. Thks. Learnt
something new!
Rick - i will try this out, very unusual to say the least, how would u
do it if the cell contained a formula. Will give it a shot over the
weekend and chk back on Monday no internet access!!!
Thks to both of u.
Hav a lovely weekend
Kz