Filter via VBA

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
144
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Attached is a small portion of the table Which has 100's nay 1000's of lines,and i need a way to filter direct from VBA "USERFORM".

This works to filter just 1 Column (Granted more than 3 options to choose from, but I only need 3 of the options to sort through)
(Promo Choice)

VBA Code:
Sub Promo_Choice_1_2_3()
    Worksheets("Rates").Range("$A$1:$L$280242").AutoFilter Field:=4, Criteria1:=Array( _
        "1Y", "2Y", "3Y"), Operator:=xlFilterValues
End Sub

This works if I change a particular cell via worksheet change for (Item)

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
   If Target.Address = Range("N2").Address Then
       Range("$A$1:$L$280242").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("N1:N2")
   End If
End Sub

This works for Price code, which has muti-options as well

VBA Code:
Sub Price_Code_Combo()
    Worksheets("Rates").Range("$A$1:$L$280242").AutoFilter Field:=7, Criteria1:=Array( _
        "USA", "Canada", "Mexico"), Operator:=xlFilterValues
End Sub

What I need is a way to do all of these via VBA, and keep filters as they go, for example If I choose (per image) Item = AAOY, Promo Choice = 2Y, and Price Code = USA , the end result will filter to Only show AAOY 2Y USA Items. When ever i try to do this, it only does 1 at a time I can't narrow it down... IE if i select AAOY it'll show all AAOY Options, but then if I choose 2Y it now shows ALL Journals that have 2Y vs just showing all AAOY 2Y options.

With 1000's of lines I need filters to narrow down without me having to use the sheet itself.

Sample of what I am trying to attempt, but keep getting errors

VBA Code:
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Worksheets("Rates").Range("N2") = Me.ComboBox1.Value
Worksheets("Rates").Range("$A$1:$L$280242").AutoFilter Field:=2, Criteria1:=Array(Worksheets("Rates").Range("N2")), Operator:=xlFilterValues
End Sub
 

Attachments

  • Rate look up.png
    Rate look up.png
    12.7 KB · Views: 22

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Well Figured it out. But now I have a new question. Will start a new thread!!
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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