dreid1011
Well-known Member
- Joined
- Jun 4, 2015
- Messages
- 3,633
- Office Version
- 365
- Platform
- Windows
I just wrote up a small bit of code to delete rows based on results of a CountIf and CountA. I tried looking up alternatives to using these with WorksheetFunction once I realized the code was taking a long time to run, but I came up empty.
So, if I find the need to employ this code again in the future, I would like to at least know what can be changed to make it run faster.
I ran it on about 8000 rows, and it took 10-15 minutes to delete ~3000 rows.
The code is looking for duplicate rows based on account number in col d, and deleting the row if it is a duplicate AND columns S, T, U are empty.
So, if I find the need to employ this code again in the future, I would like to at least know what can be changed to make it run faster.
I ran it on about 8000 rows, and it took 10-15 minutes to delete ~3000 rows.
The code is looking for duplicate rows based on account number in col d, and deleting the row if it is a duplicate AND columns S, T, U are empty.
Code:
Sub CDelRows()
Dim lRow As Long, i As Long
lRow = Range("A" & Rows.Count).End(xlUp).Row
'MsgBox lRow
Application.ScreenUpdating = False
For i = lRow To 2 Step -1
If WorksheetFunction.CountIf(Range("D2:D" & i), Range("D" & i).Value) > 1 Then
If WorksheetFunction.CountA(Range("S" & i & ":U" & i)) = 0 Then
Range("A" & i).EntireRow.Delete
End If
End If
Next i
Application.ScreenUpdating = True
End Sub