ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Auto delete a row after 5 weeks in Excel (https://www.excelbanter.com/excel-worksheet-functions/190462-auto-delete-row-after-5-weeks-excel.html)

Bill unsavvy

Auto delete a row after 5 weeks in Excel
 
I want to set up a prayer list for the Church. I will use rows for names,
and illnesses then put a date when it was posted. I think I need a formula
to make that row delete after 5 weeks. How do I make a row on an Excel
spreadsheet completely delete after a set time frame?

Dave

Auto delete a row after 5 weeks in Excel
 
Hi,
If your dates are in Column C, and your data starts in row 2, try this small
macro:

Sub DeleteOld()
A = 0
Do Until Range("C2").Offset(A, 0) = ""
If Range("C2").Offset(A, 0) < Date - 35 _
Then Range("C2").Offset(A, 0).EntireRow.ClearContents
A = A + 1
Loop
End Sub

If your dates start in some other cell, change the 3 instances of C3 to the
first date cell reference.

Right click the sheet tab, select View Code, paste the above into the VBA
window.
You can use a button to fire the macro, which will delete each entry that's
passed its use-by date.

If you want this to happen automatically, you'll need to change the code
slightly and put it somewhere else. Let me know.

Note: This deletes the whole row, which makes it simple to write code, but
undesirable if you have other info in columns to the right.

Regards - Dave.


All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com