airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
I'm trying to Autofilter my record and works well with Non-Date criteria and on recorded Macro (with Date Criteria)
but not with Date criteria selected from a covered period.
I attached the sample Workbook and my sample code here
What I'm trying to do here is to be able to autofilter and select From and To Date (Covered Period) and Client Remarks (Col D)
but not with Date criteria selected from a covered period.
I attached the sample Workbook and my sample code here
What I'm trying to do here is to be able to autofilter and select From and To Date (Covered Period) and Client Remarks (Col D)
VBA Code:
Option Explicit
'
' using CalendarForm @ https://trevoreyre.com/portfolio/excel-datepicker/
'
Private Sub btnStart_Click()
Dim StartDate As Date
StartDate = CalendarForm.GetDate
txtStart.value = Format(StartDate, "yyyy.mm.dd")
End Sub
Private Sub btnEnd_Click()
Dim EndDate As Date
EndDate = CalendarForm.GetDate
txtEnd.value = Format(EndDate, "yyyy.mm.dd")
End Sub
Private Sub btnFILTER_Click()
Dim LastRow As Long
LastRow = Worksheets("TEMP").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
' Working Showing Filtered Data
Worksheets("TEMP").Range("A2:AS" & LastRow).AutoFilter Field:=4, Criteria1:="BU*"
' Working But not showing Expected Result
Worksheets("TEMP").Range("A1:D" & LastRow).AutoFilter Field:=2, Operator:=xlFilterValues, _
Criteria1:=">=" & txtStart, Operator:=xlAnd, Criteria2:="<=" & txtEnd
' Code from Macro Recording
ActiveSheet.Range("$A$1:$D$390").AutoFilter Field:=2, Operator:= _
xlFilterValues, Criteria2:=Array(1, "1/31/2023", 1, "5/31/2023")
ActiveSheet.Range("$A$1:$D$390").AutoFilter Field:=4, Criteria1:="BUYER"
End Sub