Hi I created a macro to delete rows in an excel sheet that I did not want. I'll have a worksheet with 30k+ rows in it but want to reduce it to only rows that have a specific value in column L. The macro is just a simple while loop but the runtime will be 40 mins or more and I'm not sure why. Does anyone know why this could take so long? Here is the VBA code:
Sub Delete_Ok_Rows()
Dim Counter As Long
Dim NumRows As Long
Dim RowCount As Integer
'Delete Points Classified as "OK"
NumRows = Cells(1, 17).Value
Counter = NumRows + 3
While Counter >= 5
'
If Cells(Counter, 11).Value = "OK" Then
Rows(Counter).EntireRow.Delete
End If
Counter = Counter - 1
Wend
'Delete Points Outside the Envelope
NumRows = Cells(1, 17).Value
Counter = NumRows + 3
While Counter >= 5
'
If Cells(Counter, 14).Value = "Yes" Then
Rows(Counter).EntireRow.Delete
End If
Counter = Counter - 1
Wend
End Sub
Bookmarks