VBA Excel 2007 help to speed up code to hide rows [closed]
Try adding Application.ScreenUpdating = False
just before your hiding code, and add Application.ScreenUpdating = True
after your hiding code. Normally this trick speeds up most VBA macros by about 10x because the application does not have to keep redrawing itself as the code runs.
This should help in your case because you are checking each cell individually and hiding the row individually versus doing a batch hide of rows.
I don't see how your code even works.
You have the following 2 lines
If Not IsEmpty(cell) Then
If cell.Value = "" Then
If the first line is not empty, then 2nd line will always return false. The first line is saying "if the cell is not empty" and the next line says "if the line is empty"... Well, it's already been evaluated to not be empty. Therefore, you should never be able to hide the row so I'm lost as to how your code works - I suspect there is something else going on outside the code but...
However, this works fine on my machine
Sub Button1_Click()
Dim cell As Range
For Each cell In Range("A1:A1600")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
End If
Next
End Sub
I have 1600 rows, it takes 5 seconds or so to execute