Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
I`ve written a code see below but it only filters on the Criteria1, not Criteria1 & 2
Can`t work out why any ideas? thanks in advance
Can`t work out why any ideas? thanks in advance
VBA Code:
Private Sub Filter_Dates_Click()
Dim StDate As Object
Dim EndDate As Object
Dim ws As Worksheet
Dim Fws As Worksheet
Dim LRow As Long
Dim Tbl As ListObject
Dim Rng As Range
Dim Ary As Variant
Set ws = ThisWorkbook.Worksheets("TGS JOB RECORD")
LRow = ws.Cells(Rows.Count, 2).End(xlUp).Row
Set Rng = ws.Range("J2:J" & LRow)
Application.ScreenUpdating = False
Set StDate = Me.cmbStart_Month
Set EndDate = Me.cmbEnd_Month
On Error Resume Next
ws.ShowAllData
If StDate >= EndDate Then
MsgBox "Your Start Date is wrong"
Exit Sub
End If
If IsEmpty(StDate) Or IsEmpty(EndDate) Then
MsgBox "You need to sdd the beginning and end dates"
Exit Sub
End If
With Rng
.Autofilter Field:=10, Criteria1:=">=" & StDate, Operator:=xlAnd, Criteria2:="<=" & EndDate
End With
' ws.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub