(Solved) – How to filter out data using dates

  • by
(solved)-–-how-to-filter-out-data-using-dates

I am trying to filter out dates based on the quarter inputed into the input box but it keeps throwing an error. I am a bit new to vba and still learning. Any help will be appreciated. Thanks.
This is what I have come up with so far.

ResponseYr = SdrYear
ResponseQtr = SdrQtr

If ResponseQtr = 1 Then
BeginDate = "1 / 1 /" & ResponseYr & "0:00"
BeginDate = DateSerial(ResponseYr, 1, 1)
EndDate = "31 / 3 /" & ResponseYr & "0:00"
EndDate = DateSerial(ResponseYr, 3, 31)
'Quarter1 = Range("BeginDate:EndDate")


ElseIf ResponseQtr = 2 Then
BeginDate = "1 / 4 /" & ResponseYr & "0:00"
BeginDate = DateSerial(ResponseYr, 4, 1)
EndDate = "30 / 6 /" & ResponseYr & "0:00"
EndDate = DateSerial(ResponseYr, 6, 30)
'Quarter2 = Range("BeginDate:EndDate")

ElseIf ResponseQtr = 3 Then
BeginDate = "1 / 7 /" & ResponseYr & "0:00"
BeginDate = DateSerial(ResponseYr, 7, 1)
EndDate = "30 / 9 /" & ResponseYr & "0:00"
EndDate = DateSerial(ResponseYr, 9, 30)
'Quarter3 = Range("BeginDate:EndDate")

ElseIf ResponseQtr = 4 Then
BeginDate = "1/10/" & ResponseYr & "0:00"
BeginDate = DateSerial(ResponseYr, 10, 1)
EndDate = "31 / 12 /" & ResponseYr & "0:00"
EndDate = DateSerial(ResponseYr, 12, 31)
'Quarter4 = Range("BeginDate:EndDate")
End If
With ActiveSheet.Range("A:AD")
'.AutoFilterMode = False
.AutoFilter Field:=15, Criteria1:=Array("Accept", "Alteration Change Commencement Date", "Alteration 
Reinstatement", "Alteration Manual", "Term Expire", "Claim Repudiated", "Claim Payment Done"), 
Operator:=xlFilterValues
.AutoFilter Field:=13, Criteria1:=">=BeginDate", Operator:=xlAnd, Criteria2:="<=EndDate"
 End With

Leave a Reply

Your email address will not be published. Required fields are marked *