View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default Efficient looping

On Thu, 8 Sep 2011 07:55:31 -0700 (PDT), Kieranz wrote:

Hi Ron
What i need to do is having found "1" that row must be hidden then
move down next row, check and if "1" then hide that row and so on. but
this iteration takes a long time. I had read somewhere it could be
done much faster similar to eg like Find dialog wherein you can find
all in one go do a Control + A to select all found and then do the
necessary like hide all found rows in one go.
Rgds
Kz


It is always much more helpful to supply all of your requirements in your first post. You are more likely to obtain pertinent responses that way. As would have been the case here.


Since what you want to do is hide all the rows that contain a 1, using auto-filter would be much quicker.


Dim rg As Range
Set rg = Range("c3", Cells(3, 3).End(xlDown))
Set rg = rg.Offset(rowoffset:=-1).Resize(rowsize:=rg.Rows.Count + 1)
rg.AutoFilter Field:=1, Criteria1:="<1"

Note that in order to use this, the first row of the range will never be hidden; so we have to expand it by one. If there is a label in C2, you could set up the range that way initially.

Also note there is an optional argument for the AutoFilter to hide the dropdown box.