Results 1 to 8 of 8

delete row based on criteria - help!

Threaded 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

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