View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Efficient looping

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)