aurelius89
Board Regular
- Joined
- Mar 15, 2017
- Messages
- 69
I have some code that deletes rows that are not in a specified list of row numbers that are to be kept. It functions exactly as intended.
However, this takes a monumental amount of time. To do this on 150 rows takes a couple of minutes of processing. I have documents that could be 1000s of rows long.
Is there a better way of achieving my goal here?
Essentially I want to delete all rows on a specified sheet EXCEPT for the row numbers specified in AE4:AE?? (This is calculated by numRows) on a different sheet.
Code:
For lRow = numRowsInBBS To 1 Step -1
lMatch = 0
On Error Resume Next
lMatch = Application.Match(lRow, ws.Range("AE4:AE" & numRows).Value, 0&)
On Error GoTo 0
If Not CBool(lMatch) Then
wsImport.Cells(lRow, 1).EntireRow.Delete
End If
Next
End Sub
However, this takes a monumental amount of time. To do this on 150 rows takes a couple of minutes of processing. I have documents that could be 1000s of rows long.
Is there a better way of achieving my goal here?
Essentially I want to delete all rows on a specified sheet EXCEPT for the row numbers specified in AE4:AE?? (This is calculated by numRows) on a different sheet.
Last edited: