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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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