Mr Stanford
Board Regular
- Joined
- Sep 12, 2009
- Messages
- 142
Can anyone help on the following query?
I have taken data from a gantt chart in microsoft project and am looking to filter between dates by dropdown boxes and a macro button, this is to show all of the activities that are happening between the selected dates.
I have the start date in column 6 and the finish date in column 7.
I would like the user to select a start date and an end date and any task name item that occurs between those dates are shown.
Currently I have the code as shown below, but I know it is wrong as it filters the start date, then filters the start date results and add the finish date filter to the existing filter.
I have taken data from a gantt chart in microsoft project and am looking to filter between dates by dropdown boxes and a macro button, this is to show all of the activities that are happening between the selected dates.
I have the start date in column 6 and the finish date in column 7.
I would like the user to select a start date and an end date and any task name item that occurs between those dates are shown.
Currently I have the code as shown below, but I know it is wrong as it filters the start date, then filters the start date results and add the finish date filter to the existing filter.
Code:
Sub Between()
Sheets("Sheet1").Select
If Sheets("Sheet1").AutoFilterMode Then Cells.AutoFilter
Dim lDateFrom As Long
Dim lDateTo As Long
If Range("Sheet6!L14") > Range("Sheet6!L16") Then
lDateTo = CDbl(Range("Sheet6!L14"))
lDateFrom = CDbl(Range("Sheet6!L16"))
Else
lDateTo = CDate(Range("Sheet6!L16"))
lDateFrom = CDate(Range("Sheet6!L14"))
End If
With Sheets("Sheet1")
Range("$A$4:$Q$220").AutoFilter Field:=6, Criteria1:=">=" & lDateFrom, Operator:=xlAnd, Criteria2:="<=" & lDateTo, _
Operator:=xlAnd
Range("$A$4:$Q$220").AutoFilter Field:=7, Criteria1:=">=" & lDateFrom, Operator:=xlAnd, Criteria2:="<=" & lDateTo
End With
End Sub