Dear experts,
I am working the following code. combobox1 has months jan~dec in it. combobox2 has years 2007~2009.upon selection change in combobox the auto filter should be applied according to given criteria in the code, but I am getting subscript out of range in final code line auto filter. Any idea?
thanks
Private Sub ComboBox1_Click()
If ComboBox2.Value = "" Then Exit Sub
Call FilterDates
End Sub
Private Sub ComboBox2_Click()
If ComboBox1.Value = "" Then Exit Sub
Call FilterDates
End Sub
Private Sub FilterDates()
Dim iStartMonth As Integer
Dim iStartYear As Integer
Dim dteStartDate As Date
Dim dteEndDate As Date
Dim sStartCriterion As String
Dim sEndCriterion As String
'Get Date values
iStartMonth = Me.ComboBox1.ListIndex + 1
iStartYear = Me.ComboBox2.Value
'Calculate date values and format as US Dates
dteStartDate = DateSerial(iStartYear, iStartMonth, 1)
dteEndDate = DateSerial(iStartYear, iStartMonth + 1, 1)
sStartCriterion = " >= " & Format(dteStartDate, "mm / dd / yyyy")
sEndCriterion = " < " & Format(dteEndDate, "mm / dd / yyyy")
'Apply AutoFilter
Me.ListObjects("Table1").Range.AutoFilter _
Field:=1, _
Criteria1:=sStartCriterion, _
Operator:=xlAnd, _
Criteria2:=sEndCriterion
End Sub
Bookmarks