Nate, thank you for those links. Very informative.
Diqbal,
In my very first post on this thread I suggested using AutoFilter. And now, after seeing Tommy Bak comments on the thread that Shades started regarding Replacement Function Speed, I decided this might warrant further investigation and I can only say WOW
Tommy was quite right. AutoFilter is the way to go. I also ran my straight looping code against code using .Find and at least for me, the straight looping code ran faster.
Here's the code using autofilter:
<font face=Courier New>
<SPAN style="color:#00007F">Sub</SPAN> HideUsingAutoFilter()
<SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet
<SPAN style="color:#00007F">Dim</SPAN> rngBottom <SPAN style="color:#00007F">As</SPAN> Range, rngBig <SPAN style="color:#00007F">As</SPAN> Range, rngBig2 <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Dim</SPAN> rngToHide1 <SPAN style="color:#00007F">As</SPAN> Range, rngToHide2 <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Dim</SPAN> t <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>, f <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Byte</SPAN>
t = Timer
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> Worksheets([transpose(row(8:19))])
ws.Activate
ws.[b1].EntireColumn.Hidden = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">Set</SPAN> rngBottom = Range("H65536").End(xlUp)
<SPAN style="color:#00007F">Set</SPAN> rngBig = Range("B8:" & rngBottom.Address)
<SPAN style="color:#00007F">Set</SPAN> rngBig2 = Range("B9:" & rngBottom.Address)
rngBig.AutoFilter
<SPAN style="color:#00007F">For</SPAN> f = 1 <SPAN style="color:#00007F">To</SPAN> 7
rngBig.AutoFilter Field:=f, Criteria1:="=0.00%", Operator:=xlOr, Criteria2:="=0.0%"
<SPAN style="color:#00007F">Next</SPAN> f
<SPAN style="color:#00007F">Set</SPAN> rngToHide1 = rngBig2.SpecialCells(xlCellTypeVisible)
rngBig.AutoFilter
<SPAN style="color:#00007F">For</SPAN> f = 1 <SPAN style="color:#00007F">To</SPAN> 7
rngBig.AutoFilter Field:=f, Criteria1:="-"
<SPAN style="color:#00007F">Next</SPAN> f
<SPAN style="color:#00007F">Set</SPAN> rngToHide2 = rngBig2.SpecialCells(xlCellTypeVisible)
rngBig.AutoFilter
<SPAN style="color:#007F00">'rngToHide1.Interior.ColorIndex = 14</SPAN>
<SPAN style="color:#007F00">'rngToHide2.Interior.ColorIndex = 24</SPAN>
rngToHide1.EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN>
rngToHide2.EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">Next</SPAN> ws
Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
Debug.Print "AutoFilter", Timer - t
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
Here were the timing test results:
Code:
Run # Loop .Find AutoFilter
1 41.688 51.375 2.172
2 41.719 51.524 2.141
3 41.466 51.500 2.156
4 41.781 51.388 2.172
5 41.922 51.672 2.156
6 41.906 51.734 2.156
7 41.938 51.734 2.156
8 41.906 51.672 2.188
9 41.938 51.750 2.156
10 41.969 51.781 2.156
11 41.906 51.688 2.172
12 41.859 51.594 2.172
13 41.859 51.641 2.156
14 41.938 51.656 2.172
15 41.769 51.594 2.172
16 41.781 51.500 2.141
17 41.641 51.344 2.172