Clearing contents based on one cells date

bluemonster

New Member
Joined
Aug 3, 2004
Messages
7
I have a spreadsheet that lists employees sickness record, a row for each occasion of absence. The first column states the first date of sickness. I want a button to be able to update, this would consist of clearing rows that have a starting date that was more than a year ago. Can anyone help?? If more information is needed please let me know and I will try and provide more. Thanks everyone :biggrin:
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
Put this code in a standard module and assign it to a button:
Code:
Sub delOldRecords()
Dim i As Long

For i = Range("A65536").End(xlUp).Row To 1 Step -1
    If IsDate(Cells(i, 1).Value) Then
        If DateDiff("d", Cells(i, 1), Date) > 365 Then Rows(i).Delete
    End If
Next i

End Sub

Press Alt-F11 to open the VBE.
Press Control-R to open the Project Explorer.
Click "Microsoft Excel Objects" for the file you're working on.
Select Insert, Module from the menu.
Open the Code pane with F7.
Paste the above code in.
Press Alt-Q to close the VBE and return to Excel.

Hope that helps!
 

Forum statistics

Threads
1,147,508
Messages
5,741,571
Members
423,668
Latest member
Audorin

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
Top