The user is trying to hide row that are less than current month of last year.
Sub dHide() Application.ScreenUpdating = False Dim i As Long Dim lr As Long Dim answer As Date answer = DateAdd("m", -12, Date) lr = Range("J" & Rows.Count).End(xlUp).Row For i = lr To 3 Step -1 If Month(Range("J" & i).Value) < Month(answer) Then Range("J" & i).EntireRow.Hidden = True End If Next i Application.ScreenUpdating = True End Sub
Dates less than one year ago is what your datediff does. I read your goal as one year to the last day of the month before current month. If that was not your intent, the equality check can be easily changed. I did have to change a few of your column J values to test the criterion.
In any case, for these things, one does not have to hide by bottom up but it doesn't hurt. I like to do it all at once. e.g.
Obtained from the OzGrid Help Forum.
Solution provided by Mumps and Kenneth Hobson.
|How to use VBA code to find a match and jump to that location|
|How to use VBA code to link drop down box with pasting|
|How to use VBA code to sort worksheets based on a pre-sorted named-range|
|How to use VBA code to obtain date from cell, then calculate 3 months later|