0

Sorry for the basic question, I thought I got this but for some reason my code is only deleting one line at a time, I have to run this over and over which I thought For Each was going to handle that.

For context, I am trying to delete everything in a column that doesn't contain a specific phrase. To keep waiting down to a minimum, I set the range dynamically instead of looping through every cell.

'Delete everything that isn't Customer Owned from Column F

'Dynamically get the last row number
Dim Last_InstallStatus As Long
Last_InstallStatus = Cells(Rows.Count, 6).End(xlUp).Row

Dim InstallStatus As Range
For Each InstallStatus In Range("F2:F" & Last_InstallStatus)
    If Not InstallStatus.Value = "Customer Owned" Then
        InstallStatus.EntireRow.Delete
    End If

Next InstallStatus

Any Ideas? Or is this my machine bugging out? Thank you

  • you need to do a normal for loop and loop backwards. `For i = Last_InstallStatus to 2 Step -1` Then you would: `If Not Range("F" & i) = "Customer Owned" Then` and `Row(i).Delete` – Scott Craner Aug 08 '22 at 16:54
  • 1
    Skip the loop and use `AutoFilter` as detailed in the first linked thread. – BigBen Aug 08 '22 at 16:57

0 Answers0