VBA to delete entire row if cell matches the exact whole word

  • Hi All,
    Currently I am using the below code to delete the entire row if the mentioned strings matches in the cell value. I need a modification whereas, the row needs to be deleted if the cell matches the exact word.


    For example: If column B consist words like "test" and "latest" the code only needs to delete the word "test" leaving "latest".


    Thanks.


    Code
    strWords = "zz,*test*,tst"    For lng = LBound(Split(strWords, ",")) To UBound(Split(strWords, ","))
        Do
        On Error Resume Next
        rng.EntireRow.Delete
        Set rng = Cells.Find(What:=Split(strWords, ",")(lng), LookAt:=xlPart, MatchCase:=True)
        Err.Clear: On Error GoTo 0
        Loop Until rng Is Nothing
        Next lng
  • Re: VBA to delete entire row if cell matches the exact whole word


    Hi CodeNerd


    Perhaps remove the Wildcard from in front of *test* becoming test*

  • Re: VBA to delete entire row if cell matches the exact whole word


    Hi Jaslake


    No luck... :( It's still removing the word "latest" also.


    Quote from jaslake;786837

    Hi CodeNerd


    Perhaps remove the Wildcard from in front of *test* becoming test*

  • Re: VBA to delete entire row if cell matches the exact whole word


    Well, you could change xlPart to xlWhole...a Sample File would be good so we can help you debug.

  • Re: VBA to delete entire row if cell matches the exact whole word


    Hi CodeNerd


    Please include your existing Code in your Sample File. Please make sure the Structure of your Sample File is of the same Structure as your Actual File. Please include a Worksheet that demonstrates your expected results.

Participate now!

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