Multiple Criteria Filter VB

Arjun.Singh

Board Regular
Joined
Apr 5, 2012
Messages
62
Hello,

I have a sheet with data arranged in 5 column: State, Date, Quarter, Year and Funds.

The columns quarter and year are derived from using date.

I need a userform to gather the filters (user inputs of state & year) and the filter the data. What I intend to do is to write code to provide sum of funds for a given state & year (or a quarter if required) and save the results in a new file or print.

Ex.

State Date Year Quarter Funds
TX 11-11-2009 2009 Q3 10000$
TX 07-04-2008 2008 Q4 10000$
PA 26-02-2010 2010 3000$

What I do is filter on state (i.e. Texas,) then year, and if required, quarter to derive the rows meeting the criteria.

This is the code only for filtering:

Code:
If DTPicker1.Value = Year(Date) And ComboBox2.Value = "" Then

Worksheets("Review").Range("A1").AutoFilter Field:=1, Criteria1:=ComboBox1.Value 'State Funds All
MsgBox ("First IF")
lastrow = Range("A" & Rows.Count).End(xlUp).Row

Else

    If DTPicker1.Year <> Year(Date) And ComboBox2.Value = 0 Then
    
    Worksheets("Review").Range("A1").AutoFilter Field:=1, Criteria1:=ComboBox1.Value 'State
    Worksheets("Review").Range("A1").AutoFilter Field:=3, Criteria1:=Year(DTPicker1.Value) 'Till this year
    MsgBox ("Second IF")
    
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
    Else
    
      If DTPicker1.Year <> "" And ComboBox2.Value <> 0 Then
      
      Worksheets("Review").Range("A1").AutoFilter Field:=1, Criteria1:=ComboBox1.Value 'State
      'MsgBox ("State")
      Worksheets("Review").Range("A1").AutoFilter Field:=3, Criteria1:=Year(DTPicker1.Value) 'Year
      Worksheets("Review").Range("A1").AutoFilter Field:=4, Criteria1:=ComboBox2.Value 'Quarter
      MsgBox ("Third IF")
      
      lastrow = Range("A" & Rows.Count).End(xlUp).Row

       ' If lastrow < 2 Then
       ' MsgBox ("No such data exists, please select different quarter")
       ' With ActiveSheet
        '     If .AutoFilterMode Then
         '   .ShowAllData
         '   End If
        'End With
        'End If
        
      End If
    End If
End If

End Sub
Many thanks for any help :)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,215,615
Messages
6,125,854
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top