--- put following code In a module without the --- marks
Option Explicit
Sub filter_less_then_today()
Dim dDate As Date
Dim lDate As Long
Dim answer As Long
dDate = DateSerial(year(Now), month(Now), day(Now))
lDate = dDate
If Worksheets(1).AutoFilterMode = True Then
answer = MsgBox("Turn autofilter off (yes)" & vbCrLf & _
"Filter on date until now (no)" & vbCrLf, vbYesNoCancel, "Filtering ...")
Select Case answer
Case 6
Range("B1").AutoFilter
Case 7
Case 2
End Select
Else
answer = MsgBox("Filter on date until now (yes)" & vbCrLf & _
"Do nothing and leave it as it is (no)" & vbCrLf, vbYesNo, "Filtering ...")
Select Case answer
Case 6
Range("B1").AutoFilter field:=1, Criteria1:="<" & lDate
Case 7
End Select
End If
End Sub
--- End of code module
|