Hello,
I have a table of data which has a date column with dates in a very strict format (dd/mm/yyyy).
I have a userform with a bit of VBA script behind it to prompt a user for a "START" date and a "END" date. I need to filter my table to show only the entries between these two dates, copy it into a new worksheet and then show it.
I've got all the code together but the filter won't work, it just shows every record.
This is what I have so far:
Now I wasn't sure how to do this initially, so I used the 'record macro' and got the basic structure off it and made a few modifications... any help?
I have a table of data which has a date column with dates in a very strict format (dd/mm/yyyy).
I have a userform with a bit of VBA script behind it to prompt a user for a "START" date and a "END" date. I need to filter my table to show only the entries between these two dates, copy it into a new worksheet and then show it.
I've got all the code together but the filter won't work, it just shows every record.
This is what I have so far:
'Declare variables
Dim dtmFrom As Date
Dim dtmTo As Date
Dim intRCount As Integer
'Check if date inpts are valid and then assign user inputs to variables
If IsDate(FromDate1) Then
dtmFrom = DateSerial(Year(FromDate1), Month(FromDate1), Day(FromDate1))
Else: dtmFrom = MsgBox("Please enter a valid ""FROM"" date.", vbCritical + vbOKOnly)
Exit Sub
End If
If IsDate(ToDate1) Then
dtmTo = DateSerial(Year(ToDate1), Month(ToDate1), Day(ToDate1))
Else: dtmFrom = MsgBox("Please enter a valid ""TO"" date.", vbCritical + vbOKOnly)
Exit Sub
End If
If ToDate1.Value < FromDate1.Value Then
dtmFrom = MsgBox("Please ensure the TO Date is after the FROM Date.")
Exit Sub
Else: End If
'Create a new Summary Worksheet
Worksheets.Add(After:=Worksheets(4)).Name = "SummaryWorksheet"
'Populate Orders Summary
Sheets("Orders").Select
intRCount = ActiveSheet.UsedRange.Rows.Count
'Auto Filter table for viewing
Range("$A$1:$F$" & intRCount).AutoFilter
ActiveSheet.Range("$A$1:$F$" & intRCount).AutoFilter Field:=1, Criteria1:=">=" & dtmFrom, Operator:=xlAnd, Criteria2:="<=" & dtmTo
Range("$A$2:$F$" & intRCount).Select
Selection.Copy
Sheets("SummaryWorksheet").Select
Range("A9").Select
ActiveSheet.Paste
Sheets("Orders").Select
Application.CutCopyMode = False
Now I wasn't sure how to do this initially, so I used the 'record macro' and got the basic structure off it and made a few modifications... any help?