Help with this filter macro?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone

I have this macro to filter dates but I need to be able to combine the two so it does both things



So basicly it currently chages the filter to just
"Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:="<=" & EndM"

I need it to do both?

Code:
StartM = Sheets("Dashboard Data1").Range("B12").Value
EndM = Sheets("Dashboard Data1").Range("B14").Value


If StartM <> 0 Then
Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:=">=" & StartM
Else
Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:=">=01/01/2014"
End If


If EndM <> 0 Then
Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:="<=" & EndM
End If
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi, I'm not completely clear what you mean by doing both things, but I'm guessing you mean set the filter so that it shows items where the data is both after the start date, and before the end date.

Here's some code that I've used for a similar situation, maybe you can adapt it.

Code:
        Selection.AutoFilter Field:=1, Criteria1:=">=" & Startdate, Operator:=xlAnd, Criteria2:="<=" & Enddate
 
Upvote 0
Tony,

I believe this is what you are looking for. I modified the If statement and the Filter

Code:
startM = Sheets("Dashboard Data1").Range("B12").Value
endM = Sheets("Dashboard Data1").Range("B14").Value




If startM <> 0 And endM <> 0 Then
Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:=">=" & startM, _
Operator:=xlAnd, Criteria1:="<=" & endM
Else
Sheets("PropPDD").Range("$A$2:$J$10000").AutoFilter Field:=1, Criteria1:=">=01/01/2014"
End If
 
Upvote 0
Thanks you Frank AL and Gerald,

You have both been very helpful,
If I'm being honest frank its not quite what I wanted but you have given me the code I needed so I can change it to do what I wanted so thank you very much :-)
Tony
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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