Conditional autofilter on multiple fields in one autofilter

I am creating some encoding for a macro of macro statements and I am checking if there is such a thing as a conditional autofilter for multiple fields i.e.

TSOA.Range.AutoFilter Field:=8, Criteria1:="Unpaid", Operator:=xlOr, Field:=9, Criteria2:=">" & Dbl3M

      

So I need entries that are either unpaid or within 3 months of this month (not mutually exclusive, so only those that are really filtered are paid and older than 3 months ago). Therefore, any recordings after 28/02/2015, paid or unpaid, must be included (I know this sound is complex).

Anyway, if that doesn't work, I have some workarounds up my sleeve, auto-filtering them on individual criteria, adding them both to the same array, and removing duplicates! I just wanted to know the limitations of the autofilter feature and if it can actually be done. Thank.

An illustration of how it works:

enter image description here

So I randomly made entries up to 04/14/2015 as "Paid". The filter filter filters up to 3 months of data left over from the last month (May-2), it should also include "unpaid" records from older than 3 months ago, and include "paid" records for 3 months.

Here are some of the rest of the code in case it helps you understand:

Private Sub FilterButton2_Click()

Dim Balance As Double
Dim DblMonth As Double

With ThisWorkbook

Set TSOA = .Worksheets("SOA").ListObjects(1)
DblMonth = CLng(DateSerial(Year(Date), Month(Date), 0)) 'integer value of last month last day
Dbl3M = CLng(DateSerial(Year(Date), Month(Date) - 2, 0)) 'integer value of 3 months ago last day

If TSOA.AutoFilter.FilterMode = True Then
    TSOA.AutoFilter.ShowAllData
    TSOA.ListColumns(10).DataBodyRange.ClearContents
    Exit Sub
Else: str3 = InputBox("Please input client initials", "Client filter")
    If Application.WorksheetFunction.CountIf(.Worksheets("SOA").Range("D:D"), str3) = 0 Or str3 = "" Then
    MsgBox "Client cannot be identified!", , "Error"
    Exit Sub
    End If
End If

**ActiveSheet.AutoFilterMode = False
TSOA.Range.AutoFilter Field:=4, Criteria1:=str3
    TSOA.Range.AutoFilter Field:=8, Criteria1:="Unpaid", Operator:=xlOr, Field:=9, Criteria2:=">" & Dbl3M**

For K = 1 To TSOA.ListRows.Count

If Not TSOA.DataBodyRange.Rows(K).Hidden Then
    Balance = Balance + TSOA.DataBodyRange(K, 6).Value
    TSOA.DataBodyRange(K, 10).Value = Balance
End If
Next

End With
End Sub

      

+3


source to share


1 answer


I think AutoFilter works with one column (field: = 1 or field: = 8, etc.). It can accept multiple criteria, but with a limited value in each field

Another solution could be with formulas (if you can use a temporary column)

Formula: =OR( B2="Unpaid", AND(B2="Paid", A2 < 4) )



...

enter image description here

My dates are: 1 = This month, 2 = Last month, etc.

+2


source







All Articles