+ Reply to Thread
Results 1 to 5 of 5

VBA Autofilter multiple criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Budapest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Question VBA Autofilter multiple criteria

    Hello,
    Could anyone be so kind to help me to solve the last step in this code?


    Sub delete_error()
    
    ActiveSheet.Unprotect (password)
    With ActiveSheet
        .AutoFilterMode = False
        With Range("g4", Range("g" & Rows.Count).End(xlUp))
            .AutoFilter 1, "*Error*"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
    ActiveSheet.Protect (password), DrawingObjects:=True, Contents:=True, Scenarios:=True, _
                         AllowSorting:=True, AllowFiltering:=True
    End Sub
    I would like to have another criteria in the filter ("Do not check"), but I could not figure out how to make it.
    Many thanks
    Last edited by arlu1201; 01-29-2013 at 04:27 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Autofilter multiple criteria

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.

    Also,

    Is this solved?

    If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    Budapest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA Autofilter multiple criteria

    Hello,

    thank you for the help, I am pretty new at this forum thing. So I hit the #, see if it works
    The solution below works well, although it turned out I can not use the autofilter because of other macros used in the same file,so i need to find another solution.

    Sub delete_error()
    
    ActiveSheet.Unprotect (password)
    With ActiveSheet
        .AutoFilterMode = False
        With Range("g4", Range("g" & Rows.Count).End(xlUp))
            .AutoFilter Field:=1, Criteria1:=Array("*Error*", "*Do not check*"), Operator:=xlFilterValues
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
    ActiveSheet.Protect (password), DrawingObjects:=True, Contents:=True, Scenarios:=True, _
                         AllowSorting:=True, AllowFiltering:=True
    End Sub

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Autofilter multiple criteria

    Ok, in that case, i will mark your thread as "Unsolved" so that others can help you.

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Budapest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA Autofilter multiple criteria

    Hi,

    thank you.
    I have tried following code:

    Private Sub CommandButton2_Click(a As String)
        
        For a = 1 To WorksheetFunction.CountA(Range("G:G"))
            If a = "*Error *" Then
            EntireRow.Delete
                If a = "Do not check*" Then
                EntireRow.Delete
                End If
           End If
        Next
    
    End Sub
    I am trying to add it to a button as well. Unfortunately it is not working in any kind of way.
    Can anybody help with this one?
    Thanks a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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