Delete Rows containing a certain textstring
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: Delete Rows containing a certain textstring

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Philippines
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I am using Excel 2000.
    I have a spreadsheet with 55000 e-mail addresses in column A. In order to remove duplicates I used the following macro code:
    Sub delete_duplicates()
    rowx = 1
    Do Until Cells(rowx + 1, 1).Value = ""
    If UCase(Cells(rowx, 1).Value) = UCase(Cells(rowx + 1, 1).Value) Then
    Cells(rowx + 1, 1).EntireRow.Delete
    Else
    rowx = rowx + 1
    End If
    Loop
    End Sub

    Some of the addresses have an additional "REMOVED" added to the end of it, indicating the e-mail address is no longer valid.
    How can I modify the above code to delete those rows as well.
    Hans

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following code:

    If Right(Cells(rowx, 1).Value, 7) = "REMOVED" Then Cells(rowx + 1, 1).EntireRow.Delete

    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    Board Regular shades's Avatar
    Join Date
    Mar 2002
    Location
    Near the Land of Oz
    Posts
    1,550
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hans, thanks for the macro. I have been looking for exactly that process for a long time.

    Rich
    - old, slow, and confused
    ... but at least I'm inconsistent -

    (retired Excel 2003 user, 3.28.2008)

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Philippines
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Al Chara,
    tried it out, had to add a ")" after the word REMOVED, but it gives me the message:
    "Runtime Error 13 - type mismatch"
    What now, shoot myself?
    Hans

  5. #5
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The following code is what I am using and it works:

    rowx = 1
    If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then
    Cells(rowx, 1).EntireRow.Delete
    End If
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  6. #6
    Board Regular
    Join Date
    Mar 2002
    Location
    Philippines
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Used your code exactly and it deleted every row except the first one wich contained REMOVED in it.
    Dont worry, I had a backup.
    Gonna shoot myself anyway.

    Where is my mistake:
    Sub delete_removed()
    rowx = 1
    Do Until Cells(rowx + 1, 1).Value = ""
    If Right(Cells(rowx, 1).Value, 7 = "REMOVED") Then
    Cells(rowx + 1, 1).EntireRow.Delete
    Else
    rowx = rowx + 1
    End If
    Loop
    End Sub

    Hans

  7. #7
    Board Regular
    Join Date
    Mar 2002
    Location
    Philippines
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sub delete_removed()
    rowx = 1
    Sorry posted the old code.
    Here is the "Killer Code"

    Do Until Cells(rowx + 1, 1).Value = ""
    If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then
    Cells(rowx + 1, 1).EntireRow.Delete
    Else
    rowx = rowx + 1
    End If
    Loop
    End Sub

  8. #8
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The following code worked for me:

    rowx = 1
    Do Until Cells(rowx + 1, 1).Value = ""
    If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then
    Cells(rowx, 1).EntireRow.Delete
    Else
    rowx = rowx + 1
    End If
    Loop

    I think you had "rowx+1" when you needed just "rowx"
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  9. #9
    Board Regular
    Join Date
    Mar 2002
    Location
    Philippines
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    IT WORKS!
    ****ty little +
    Thanks
    Hans

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com