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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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!
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

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