This code takes 40 seconds to run in 2007 but <1 second in excel 2003. Why? How can I make it run faster? Thank you in advance!
For RowCount = 1 To 1800
If ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Hidden = True
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
Next RowCount
Welcome to the MrExcel board!
I'm not sure why that would take so much longer in Excel 2007 than in Excel 2003. However, there should be faster ways in
both versions. It is generally not required to actually select cells to work with them and selecting slows your code considerably. Also, there is often an alternative to looping through every row that is much faster than the looping process.
I don't know where your ActiveCell is when this code is triggerred, or exactly what your goal is. However, as an example, if you are looking to hide zero value rows by looking down column C, and you have a heading in row 1, then you could achieve the result quickly using AutoFilter with something like this:
Code:
With Range("C1", Range("C" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="<>0"
End With
If you need it to also hide blank value rows, then change the middle line to
Code:
.AutoFilter Field:=1, Criteria1:="<>0", Operator:=xlAnd, Criteria2:="<>"
Finally, I think you meant to post your code with indentations and that is a good idea. To do that you need to use code tags. Click the 'Quote' button at the bottom of my post and you should be able to see how that is done.
If you need more help, post back with more details of just what you have in your sheet and what you are trying to do.