Results 1 to 5 of 5

How do I delete all rows containing a certain text string? / rows containg x, y. or z

Threaded View

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    31

    How do I delete all rows containing a certain text string? / rows containg x, y. or z

    Hi -- found a good script for this, but I need to delete rows that contain different variables and I don't know how to run that several times at one go - fr example delete all lines containing Fred,Paul, or Jim

    This was the original script in the previous reply to another members question: --- it requires input fr the string, but I would prefer knowing how I could just embed the terms. Thanks in advance for help on this

    Sub deleteRows()
        Dim rng    As Range
        Dim rng2   As Range
        Dim cl     As Range
        Dim str    As String
    
        str = InputBox("Enter search text", "Find & Delete")
        If str = "" Then Exit Sub
        Set rng = ActiveSheet.UsedRange
        For Each cl In rng
            If cl.Value Like "*" & str & "*" Then
                If rng2 Is Nothing Then
                    Set rng2 = cl
                Else: Set rng2 = Union(rng2, cl)
                End If
            End If
        Next cl
        rng2.EntireRow.Delete
    Moderator's Note: When posting codes. Select the code then hit "#" sign to enclose the codes with code tags. Thank you and welcome to the forum.
    Last edited by vlady; 12-18-2012 at 07:57 PM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1