VBA to filter by criteria

asjmoron

Board Regular
Joined
Apr 26, 2016
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
Hey guys,

I am trying to write a VBA way of filtering between two dates and by one criteria.

For exmaple,

I have a data on a sheet called "Sales Data" and date fields that are set in two different cells and a name in a third cell on "Dashboard". I want to be able to filter "Sales Data" based on the selections on the Dashboard Page...

Any thoughts?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Ive sussed it now!

if you are interested this what I ended up with

Public Sub SalesFilter()
Dim lngStart As Long, lngEnd As Long, IngAgent As Long


lngStart = Sheets("DashBoard").Range("J4").Value 'Start date
lngEnd = Sheets("DashBoard").Range("J5").Value 'End date
lngAgent = Sheets("DashBoard").Range("F5").Value 'Agent Name

Sheets("Sales Data").Select

Sheets("Sales Data").Range("A1:R1").Autofilter Field:=18, _
Criteria1:=">=" & lngStart, _
Operator:=xlAnd, _
Criteria2:="<=" & lngEnd

Sheets("Sales Data").Range("A1:S1").Autofilter Field:=19, _
Criteria1:="=" & lngAgent

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,923
Messages
6,175,398
Members
452,640
Latest member
steveridge

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