+ Reply to Thread
Results 1 to 8 of 8

delete row based on criteria - help!

Hybrid View

pinky24 delete row based on criteria... 03-14-2014, 01:10 PM
ANDREAAS Re: delete row based on... 03-14-2014, 01:21 PM
ANDREAAS Re: delete row based on... 03-14-2014, 01:27 PM
pinky24 Re: delete row based on... 03-17-2014, 05:48 AM
pinky24 Re: delete row based on... 03-17-2014, 10:01 AM
pinky24 Re: delete row based on... 03-17-2014, 01:02 PM
pinky24 Re: delete row based on... 03-18-2014, 10:56 AM
JOHN H. DAVIS Re: delete row based on... 03-18-2014, 11:14 AM
  1. #1
    Registered User
    Join Date
    03-14-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    delete row based on criteria - help!

    Hi,

    I thought I had worked this out from google but it seems to not do everything I want.

    Formula below works for one string, "review" but i also need it to work for "audit" "project" and "done" too.... so essentially someone can go into the sheet - hit a button and remove all these lines in one go.



    Sub Delete_Based_on_Criteria()
    
    ' This macro will delete an entire row based on the presence of a
    'predefined word or set of words.  If that word or set of words is
    'found in a cell, in a specified column, the entire row will be 'deleted
    Dim x As Long
    Dim Z As Long
    Dim lastRow As Long
    Dim FoundRowToDelete As Boolean
    Dim OriginalCalculationMode As Long
    Dim RowsToDelete As Range
    Dim SearchItems() As String
    
    Dim DataStartRow As Long
    Dim SearchColumn As String
    Dim SheetName As String
    
     
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    ' Choose the row you want the search and delete to start on
    ' Choose the column to search and delete to use for deletion
    ' Choose the sheet in the workbook you want this macro to be run on
    
    DataStartRow = 2
    SearchColumn = "E"
    SheetName = "Sheet1"
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
     
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    ' Enter the terms you want to be used for criteria for deletion
    ' All terms entered below are CASE SENSITIVE and need to be
    'seperated by a comma
    
    SearchItems = Split("Review", "")
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
     
    
    On Error GoTo Whoops
    OriginalCalculationMode = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    
    With Worksheets(SheetName)
    lastRow = .Cells(.Rows.Count, SearchColumn).End(xlUp).Row
    For x = lastRow To DataStartRow Step -1
    FoundRowToDelete = False
    For Z = 0 To UBound(SearchItems)
    If InStr(.Cells(x, SearchColumn).Value, SearchItems(Z)) Then
    FoundRowToDelete = True
    Exit For
    End If
    
    Next
    
    If FoundRowToDelete Then
    If RowsToDelete Is Nothing Then
    Set RowsToDelete = .Cells(x, SearchColumn)
    Else
    Set RowsToDelete = Union(RowsToDelete, .Cells(x, SearchColumn))
    End If
    
    If RowsToDelete.Areas.Count > 100 Then
    RowsToDelete.EntireRow.Delete
    Set RowsToDelete = Nothing
    End If
    End If
    
    Next
    
    End With
    If Not RowsToDelete Is Nothing Then
    RowsToDelete.EntireRow.Delete
    End If
    
    Whoops:
    Application.Calculation = OriginalCalculationMode
    Application.ScreenUpdating = True
    
     
    
    End Sub
    Last edited by pinky24; 03-18-2014 at 11:37 AM. Reason: solved

  2. #2
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: delete row based on criteria

    change this :

    ' Enter the terms you want to be used for criteria for deletion
    ' All terms entered below are CASE SENSITIVE and need to be
    'seperated by a comma
    
    SearchItems = Split("Review", "")
    to this :

    ' Enter the terms you want to be used for criteria for deletion
    ' All terms entered below are CASE SENSITIVE and need to be
    'seperated by a comma
    
    SearchItems = Split("Review", "audit","project","done")

  3. #3
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Re: delete row based on criteria

    also read the below.... the modurators frown on these things ...... see the forum rules

    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button). The result will appear like this in the post window:

    your code here ...
    and here ...
    and here
    ... and appear like this when posted:


    your code here ...
    and here ...
    and hereYou can also type the code tags in manually if you prefer. For more information about these and other tags, click here.

  4. #4
    Registered User
    Join Date
    03-14-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: delete row based on criteria

    sorry about that fixed it now!

    is there a way to put spaces in? it's throwing up an error and I think it's because the full category is TS Audit, TS Done.


    EDIT:

    it's coming up with Run-time error '13': Type mismatch
    Last edited by pinky24; 03-17-2014 at 05:51 AM.

  5. #5
    Registered User
    Join Date
    03-14-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: delete row based on criteria

    *bump*

    still need help with this

  6. #6
    Registered User
    Join Date
    03-14-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: delete row based on criteria

    still stuck.... :-(

  7. #7
    Registered User
    Join Date
    03-14-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: delete row based on criteria - help!

    ... anyone....

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: delete row based on criteria - help!

    Try this approach:

    Sub pinky24zz()
    Range("E1:E" & Range("E" & Rows.count).End(3)(1).Row).AutoFilter 1, "=*review*", xlOr, "=*audit*"
    Range("E2:E" & Range("E" & Rows.count).End(3)(1).Row).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.AutoFilterMode = False
    Range("E1:E" & Range("E" & Rows.count).End(3)(1).Row).AutoFilter 1, "=*project*", xlOr, "=*done*"
    Range("E2:E" & Range("E" & Rows.count).End(3)(1).Row).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.AutoFilterMode = False
    End Sub

+ 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. Delete Row based on Criteria!!
    By vignesh rocks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2012, 07:30 AM
  2. Delete row based on criteria
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2011, 10:00 AM
  3. delete rows based on a criteria
    By Ralem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2011, 06:47 AM
  4. delete based on criteria
    By numbersdntlie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2011, 09:53 AM
  5. delete row based on criteria
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-03-2010, 05:13 AM

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