ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide row automatically based on date (https://www.excelbanter.com/excel-programming/430320-hide-row-automatically-based-date.html)

munchkin

Hide row automatically based on date
 

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?


Otto Moehrbach[_2_]

Hide row automatically based on date
 

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
"Munchkin" wrote in message
...
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?




Jacob Skaria

Hide row automatically based on date
 

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
---------------
Jacob Skaria


"Munchkin" wrote:

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?



All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com