+ Reply to Thread
Results 1 to 3 of 3

VBA code for deleting Rows that contain specific criteria from Filtered Data

Hybrid View

  1. #1
    Registered User
    Join Date
    07-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    33

    VBA code for deleting Rows that contain specific criteria from Filtered Data

    Hello,

    I am trying to delete the entire row/rows of specific data from a filtered table. As an example, I have data in columns A1:E600. From Column B, I want to delete the rows that contain the text "Active".

    I have a used the following macro, but I am stuck when I want to remove the filter. Then filter on a different column and delete the criteria in that column.

        
       Worksheets("Sheet1").Range("A1").AutoFilter Field:=1, Criteria1:="Active"
        Application.DisplayAlerts = False
        ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
        Application.DisplayAlerts = True
        Selection.AutoFilter
    Can someone please help or refer me to a great link?? Also, if there is a cleaner way than this code, please advise.

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: VBA code for deleting Rows that contain specific criteria from Filtered Data

    Hi

    Maybe

    Sub aaa()
      ActiveSheet.AutoFilterMode = False 'turn off any existing autofilter
      lastrow = Cells(Rows.Count, 1).End(xlUp).Row 'assumes there will always be an entry in column A
      Range("A:E").AutoFilter field:=2, Criteria1:="Active" 'filter on column B
      On Error Resume Next
      Range("A2:E" & lastrow).SpecialCells(xlCellTypeVisible).EntireRow.Delete shift:=xlUp
      On Error GoTo 0
      Range("A:E").AutoFilter field:=4, Criteria1:="thisone"  'filter on column D
      On Error Resume Next
      Range("A2:E" & lastrow).SpecialCells(xlCellTypeVisible).EntireRow.Delete shift:=xlUp
      On Error GoTo 0
      ActiveSheet.ShowAllData
      ActiveSheet.AutoFilterMode = False
      
    End Sub
    rylo

  3. #3
    Registered User
    Join Date
    07-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: VBA code for deleting Rows that contain specific criteria from Filtered Data

    rylo,

    Thanks, this worked!

    Carlos

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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