• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Can this macro be speeded up

Cammandk

Member
I am using the code below to hide rows that are not relevant to print and/or copy just relevant data to another sheet.

The code below looks at all the rows in Col A and if they =0 it hides the rows.
This seems to be taking a lot longer than it initially did.

It looks through approx. 2000 rows.

Can it be made faster or some progress bar added?


Code:
Sub PrintBudgetRows()
Dim cel As Range
Dim rng As Range

  'Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual
 

  Set rng = Sheets("Budget").Range("A10", Range("EndOfBudgetRange"))
  
  rng.AutoFilter Field:=1, Criteria1:="<>0"
  For Each cel In rng
  If cel.Value = 0 Then
  cel.EntireRow.Hidden = True
  
  End If
  
  Next cel
  
  
  Application.ScreenUpdating = True
  Application.Calculation = xlCalculationAutomatic
  
End Sub


Thanks
DK
 
I'm confused at your code. You already have a line to filter the data, which is the fastest way. Why do you then loop through all the cells? Isn't the filter line enough? I.e., I don't think the entire For...Next loop is needed.
 
Whenever using a filter you should clear the filter first
Otherwise you risk adding this filter to any existing filters
Code:
  ActiveSheet.ShowAllData
 
Back
Top