Delete entire row if a cell does not match the keyword/data

  • Hello Everyone,


    Good day.
    I am new to the group.
    I need to know how to create a macro that will delete an entire row if a cell does not match the keyword/data.


    I have attached a sample report that needs the macro. in the file under column R, the USI - GSC - L1 should be left, and delete other rows.


    Thank you,
    Jomarie

  • Re: Delete entire row if a cell does not match the keyword/data


    Hi Jomz07


    Welcome to the Forum!!!


    Try this Code in a General Module...

  • Re: Delete entire row if a cell does not match the keyword/data


    Hello jaslake,


    Thank you for the above code. Tested and working. It leaves the USI - GSC - L1.
    Just to clarify, does the code filters only in column F of my workbook?


    Apologies, I have little background in codes.


    Thank you,
    Jomz07

  • Re: Delete entire row if a cell does not match the keyword/data


    Hi Jomz07


    Sory for the delayed response...didn't get Email Notification.


    Yes, this Line of Code says to Filter Column 6 (F)...

    Code
    .Range("$A$2:$JH" & LR).AutoFilter Field:=6, Criteria1:= _ 
      "<>USI - GSC - L1", Operator:=xlAnd



  • Re: Delete entire row if a cell does not match the keyword/data


    jaslake,


    in that case, if I change Field:=6 to, let's say 3, would that be filtering column 3?


    Thank you,
    Jomz07

  • Re: Delete entire row if a cell does not match the keyword/data


    Hi Jomz07


    Yes, this is correct...

    Quote

    if I change Field:=6 to, let's say 3, would that be filtering column 3?


    However, if your Filter Range reads like this Column C would be 2...

    Code
    .Range("$B$2:$JH" & LR).AutoFilter Field:=2


    Further, if it reads like this Column C would be 1...

    Code
    .Range("$C$2:$C" & LR).AutoFilter Field:=1

Participate now!

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