Much as the title says. I have the following piece of VBA code:
Sub Filtering()
Application.ScreenUpdating = False
Numrows = Range("L6").Value
Num_Unique_Codes = Range("J6").Value
For i = 20 To Num_Unique_Codes
Name = Range("O20:O" & i)
Range("A19:L" & Numrows).AutoFilter Field:=7, Criteria1:=Name
Range("K5") = Application.Sum(Range("C20:C" & Numrows).SpecialCells(xlCellTypeVisible))
If Range("K5") = 0 Then
Range("A20:L" & Numrows).SpecialCells(xlCellTypeVisible).Clear
End If
ActiveSheet.ShowAllData
Next i
Application.ScreenUpdating = True
End Sub
This works 100% perfectly from a functionality point of view, but is very slow. I know enough about vba to understand that it is likely due to how often I am changing physical excel cells instead of dealing with a range, but not enough to no where to go with fixing it.
I've attached an excel file that shows what it does. Macros 1-4 work. Macro 5 (the code included above) is the slow one, although it works.
Functionality Wise, this is what I'm doing:
Counting the rows (quick enough)
Finding all the unique names and counting them (quick enough)
Filtering by each unique name, and if the values of each unique name sum to 0, clearing the cells (this is slow)
Tidying up by deleting all the unique names and all the rows I cleared.
Any help appreciated
Bookmarks