Faster Way of Grouping Rows using Loops in VBA

Viewed 101
For k = 1 To 25000     
   z = Sheet6.Range("E4").Offset(k, 0)
   If (z = 3 Or z = 4) Then
      Range("E4").Offset(k, 0).Rows.Group
   Else
   End If        
Next k

I am trying to create a loop for grouping with a condition. If the given cell (E5, E6 and so on) value is 3 or 4 then these rows will be grouped together as in Excel function "Data > Outline > Group". And this loop will run for 25000 lines, sometimes more. With my code and 25000 lines, this task takes approx. 20 minutes to run which is not ok. How can I fasten up this process? I would normally create an array to run the loop quicker but when it's "grouping" I couldn't come up with how. Bear in mind that I am using some speed-up techniques such as application calculation manual, no screen updating, no enable events. I am posting the link of an image for the end result to better explain what I need

0 Answers
Related