Optimize performance of Removing Hidden Rows in VBA
Sub RemoveHiddenRows()
With Sheets("Sheet10")
With .Cells(1, 1).CurrentRegion
With .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
If CBool(Application.Subtotal(103, .Columns(1))) Then
.Cells.Copy Destination:=.Cells(.Rows.Count + 1, 1)
End If
.AutoFilter
.Cells(1, 1).Resize(.Rows.Count, 1).EntireRow.Delete
End With
End With
End With
End Sub
I use this method to delete my hidden rows and it worked very fast. However, in my raw data, there are several cells are formulas. The RemoveHiddenRows() will turn my formulas to #DIV/0! which troubles me a lot.
My Raw Data.png Edit: The below formulas in the picture are SUM(B:B) and SUM(C:C), sorry for the consusion
For example, if I select "Amy"'s money first, and use the above code to delete others' data, my "sum" and "total" formula will disappear. How can I keep them while using the RemoveHiddenRows(). I really don't have any idea.