+ Reply to Thread
Results 1 to 2 of 2

code:Find and Delete

Hybrid View

  1. #1
    Registered User
    Join Date
    10-16-2008
    Location
    St. Louis
    Posts
    6

    code:Find and Delete

    Wrote the below VB and it worked once but I may have made a mess of things with a series of Cut and Pastes. Want Excel to find specific phrases or words in a specific column and delete them.

    Option Explicit
    
    Sub delRows()
        Dim cl     As Range
        Dim uRng   As Range
        Dim rng    As Range
        Dim x      As Long
    
        Set uRng = ActiveSheet.UsedRange
        For Each cl In uRng
            If cl.Value = "Not Rated  |  Write a Review" Or cl.Value = "Click on the More Info button to learn about this business." Or cl.Value = "More Info" Or cl.Value = "Map It" Then
                If x = 0 Then
                    Set rng = cl
                    x = 1
                Else: Set rng = Union(rng, cl)
                End If
            End If
        Next cl
        rng.EntireRow.Delete
    
    End Sub


    Attachment is included
    Attached Files Attached Files
    Last edited by billkelley; 10-09-2009 at 03:37 PM. Reason: correct code tags "#"

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    re: code:Find and Delete

    Hello billkelley,

    Aside from shortening your code a bit and preventing an error when deleting rows, I don't see any problems with it. What is not doing?
    Option Explicit
    
    Sub delRows()
        Dim cl     As Range
        Dim uRng   As Range
        Dim rng    As Range
    
        Set uRng = ActiveSheet.UsedRange
    
        For Each cl In uRng
            If cl.Value = "Not Rated  |  Write a Review" Or cl.Value = "Click on the More Info button to learn about this business." Or cl.Value = "More Info" Or cl.Value = "Map It" Then
                If rng Is Nothing Then Set rng = cl
                Set rng = Union(rng, cl)
            End If
        Next cl
        
        If rng.Rows.Count > 0 Then rng.EntireRow.Delete
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

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