I am new to VBA and I am trying to get my code to loop through about 10,000 lines of integers in row K and delete rows based on values, my code works but will only do small parts at a time. Please advise.
'Delete unwanted accounts
Dim Lcell As Long
Application.ScreenUpdating = False
Lcell = TransSheet.Cells(Rows.Count, "K").End(xlUp).Row
For a = 1 To Lcell Step 1
Select Case Cells(a, 11).Value
Case "1200", "652", "552"
Cells(a, 11).EntireRow.Delete
End Select
Next a
Application.ScreenUpdating = True
Try from the last row to the first one. You are deleting rows so your numbering is being thrown off:
You can perform a single delete on all the identified rows:
Add this line to your code
This will take care of the shifting that occurs because the row disappears.
On a side note, I personally use the following method to delete multiple rows. e.g. the rows I want to delete are stored in an
Variant
arrayDelRows()
. You may obtain them dynamically at run-time. Here I manually assign some random rows.