Hide row automatically based on date

M

Munchkin

I want my spreadsheet to look the date in colum C of each row. If the date
is more than 4 years old I'd like the row to be hidden. Any way to do this
automatically?
 
O

Otto Moehrbach

Perhaps something like this. I assumed your data in Column C starts in C2
down. HTH Otto

Sub HideRows()
Dim rColC As Range
Dim i As Range
Set rColC = Range("C2", Range("C" & Rows.Count).End(xlUp))
For Each i In rColC
If DateSerial(Year(Date) - 4, Month(Date), Day(Date)) > i.Value Then
i.EntireRow.Hidden = True
End If
Next i
End Sub
 
J

Jacob Skaria

Try the below macro..You can either run this as a macro or paste the code in
workbook Close event or Open event ...Try and feedback..

Sub HideRows()
Dim lngRow as Long
For lngRow = 1 To Cells(Rows.Count, 3).End(xlUp).Row
If DateDiff("m", Range("c" & lngRow), Date) > 48 And _
0 + Range("c" & lngRow) <> 0 Then Rows(lngRow).Hidden = True
Next
End Sub

If this post helps click Yes
 
Top