VBA Code to Select and Delete Cells with "ShipTo" in it.

  • Hi Everyone,

    I want to develop a code that would delete all the rows that contains cells with data "ShipTo" in column "E".

    The below code is doing the opposite what I want. Its deleting everything apart from "ShipTo"

    Sub Test()

    Dim rng As Range, cell As Range, del As Range

    Set rng = Intersect(Range("E:E"), ActiveSheet.UsedRange)

    For Each cell In rng

    If InStr(cell.Value, "ShipTo") = 0 Then ' delete al rows without "ShipTo"

    If del Is Nothing Then

    Set del = cell

    Else: Set del = Union(del, cell)

    End If

    End If

    Next cell

    On Error Resume Next

    del.EntireRow.Delete '

    End Sub

  • Hi and Welcome to the Forum :)

    You could test the following macro to delete rows where 'ShipTo' appears ...

    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

Participate now!

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