Delete Row If Condition Not Met

  • Here's my code:

    Code
    Sub DeleteRows()
        Dim ws As Worksheet
        Set ws = ActiveSheet
        For i = ws.Range("A65536").End(xlUp).Row To 2 Step -1
            If ws.Cells(i, 9) <> "TRENCH_TYPE" Then
                ws.Rows(i).Delete
            End If
        Next
    End Sub


    Attached is my worksheet. I want to remove everything but the header row & rows that have "Trench_Type" in column A. However it's deleting everything but my header.

  • Re: Delete Row If Condition Not Met


    Hi ,


    Replace

    Code
    If ws.Cells(i, 9) <> "TRENCH_TYPE" Then


    With

    Code
    If ws.Cells(i, 1) <> "TRENCH_TYPE" Then


    Regards,


    JL

  • Re: Delete Row If Condition Not Met


    jesus christ i'm dumb. working too hard. thanks.

    Ed
    [SIZE=6]*ficus*[/SIZE]
    Thanks to all for making this website work!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!