Unhide Rows Date Older Than 7 Days

D

Dean P.

I would like to create a macro to unhide rows in Sheet1 with Dates in Column
(C) that are older than 7 days old from current day. The Dates are in Column
(C) starting in row 2.

Please help me create this unhide macro.

Thanks,

Dean P.
 
J

Joel

Sub hiderows()

'unhide everything
Cells.Select
Selection.EntireColumn.Hidden = False
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set ColCRange = Range("C1:C" & LastRow)

For Each cell In ColCRange
If Date - cell.Value > 7 Then
Cells.EntireRow.Hidden = True
End If

Next cell


End Sub
 
J

JW

One way:
Sub this()
Rows.Hidden = False
For i = 2 To Cells(Rows.Count, 3).End(xlUp).Row
If Not IsDate(Cells(i, 3).Value) Or _
Not Cells(i, 3).Value < Date - 7 Then _
Cells(i, 3).EntireRow.Hidden = True
Next i
End Sub

This will hide anything that is not a date as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top