I have excel sheet with dates in column A, and I need to find latest date and filter last 7 days before that latest date. I only found vba codes online which takes todays date - 7 days but I cant use that because these dates are from last year.
Please and thank you!
EDIT:
Thanks for your suggestion. I tried to put it in my vba code but it filters 0 results.
Sub Filter()
Dim maxDate As Date
maxDate = WorksheetFunction.Max(ActiveSheet.Range("A:A"))
ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _
">" & maxDate - 6
End Sub
Doesn't work since this VBA macro filers date by dd.mm.yyyy. (NOTE THE DOT at the end), 0 results in my case, it should filter by dd.mm.yyyy (without dot). I dont know how to filter without dot
EDIT2: This worked for me.
Sub Largest()
Dim rng As Range
Dim dblMax As Double
Set rng = ActiveSheet.Range("A:A")
dblMax = Application.WorksheetFunction.Max(rng)
ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _
">" & dblMax - 7, Operator:=xlAnd
End Sub
5/30/2018
inA1
, inB1
you can type=A1-5
to get5/25/2018
. – BruceWayneDouble
– Ron Rosenfeld