Loop through dates in a column

Jockster

Board Regular
Joined
Jan 16, 2009
Messages
88
I would like to loop through dates in column "D" and, where a date is found to be less than today's date, to hide the entire row and then continue on to the next cell in col "D" until the last row with a date in "D".
Also, at a later time, what would be the best way to 'unhide' the hidden rows with one click?

Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Double click in column "D" to Hide rows.
Right Click In column "A" to Unhide rows.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Rng As Range, Dn As Range
Application.ScreenUpdating = False
    If Target.Column = 4 Then
        Set Rng = Range(Range("D1"), Range("D" & Rows.Count).End(xlUp))
          For Each Dn In Rng
            If IsDate(Dn) Then
                If DateValue(Dn) < Date Then
                    Dn.Rows.Hidden = True
                End If
            End If
        Next Dn
    End If
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
    If Target.Column = 1 Then
        Rows.Hidden = False
    End If
End Sub
Mick
 
Upvote 0
Nb:- Place the "Cancel = True " within the "If" statement , else you will loose the Right click short cut menus for the other columns.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,240
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top