+ Reply to Thread
Results 1 to 4 of 4

Macro to delete rows not containing multiple criteria

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    78

    Macro to delete rows not containing multiple criteria

    Hi All—

    I am trying to create a macro that searches a column ("F") to see if it contains either the word "MAINTAIN" or "REPAIR" (in a text string such as "MAINTAIN UG MTC" "MAINTAIN OH SVC" "REPAIR CONV MTC" "DISCONNECT AND REPAIR TRANSF"), keep the row if it does have either word, and delete the entire row if it does not. Here is what I have so far. It does delete some rows, but not all and I don't understand why or how to fix it.

    ==
    Sub delete_rows()
    Dim lastrow As Long
    Dim row_index As Long
    Application.ScreenUpdating = False
    lastrow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
    For row_index = lastrow - 1 To 1 Step -1
    If InStr(Cells(row_index, "F").Value, "MAINTAIN") = 0 Then
    ElseIf InStr(Cells(row_index, "F").Value, "REPAIR") = 0 Then
    Cells(row_index, "F").EntireRow.Delete
    End If
    Next
    Application.ScreenUpdating = True
    End Sub
    ==

    Thank you.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Macro to delete rows not containing multiple criteria

    Try:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-10-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    78

    Re: Macro to delete rows not containing multiple criteria

    Like a charm! Thanks SO much!

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Macro to delete rows not containing multiple criteria

    My pleasure.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. macro - delete rows based on multiple criteria.
    By ChocksterNo1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2013, 10:22 AM
  2. Replies: 9
    Last Post: 12-20-2012, 10:29 AM
  3. Delete Rows using multiple criteria
    By markhao in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2011, 10:18 PM
  4. Delete rows that match multiple criteria
    By gsrai31 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2010, 09:30 AM
  5. delete rows with multiple criteria
    By myparticulars in forum Excel General
    Replies: 2
    Last Post: 09-08-2009, 06:25 PM

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