From: Pas on
How do I create a macro that will delete entire row if older then 365 days.
Dates are on col "A"
last col of data = "U"
Data is kept in sheet "details"

Thank you
From: מיכאל (מיקי) אבידן on
If you agree to ignore lap years then the following simple code will do.
Put it into the Sheet "details" Level:
--------------------------------
Sub Del_Oldies()
LR = Cells(Rows.Count, 1).End(xlUp).Row
For R = LR To 1 Step -1
If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
Next
End Sub
--------------
Micky


"Pas" wrote:

> How do I create a macro that will delete entire row if older then 365 days.
> Dates are on col "A"
> last col of data = "U"
> Data is kept in sheet "details"
>
> Thank you
From: Pas on
Many thanks מיכאל (מיקי) אבידן

I did as suggested but get the following error message.

Compile error:
Variable not defined

any ideas?

"מיכאל (מיקי) אבידן" wrote:

> If you agree to ignore lap years then the following simple code will do.
> Put it into the Sheet "details" Level:
> --------------------------------
> Sub Del_Oldies()
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
> --------------
> Micky
>
>
> "Pas" wrote:
>
> > How do I create a macro that will delete entire row if older then 365 days.
> > Dates are on col "A"
> > last col of data = "U"
> > Data is kept in sheet "details"
> >
> > Thank you
From: Pas on
sorry i also get "LR =" highlighted in blue

"מיכאל (מיקי) אבידן" wrote:

> If you agree to ignore lap years then the following simple code will do.
> Put it into the Sheet "details" Level:
> --------------------------------
> Sub Del_Oldies()
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
> --------------
> Micky
>
>
> "Pas" wrote:
>
> > How do I create a macro that will delete entire row if older then 365 days.
> > Dates are on col "A"
> > last col of data = "U"
> > Data is kept in sheet "details"
> >
> > Thank you
From: ozgrid.com on
Try;


Sub DeleteOldDates()
Dim lDate As Long

lDate = Date - 365
With Sheets("details")
.AutoFilterMode = False
.Range("A1:A2").AutoFilter Field:=1, Criteria1:="<" & lDate
.AutoFilter.Range.Offset(1,
0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With

End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"Pas" <Pas(a)discussions.microsoft.com> wrote in message
news:1A05E0D7-7EFD-45FE-9907-8E69987FB5CD(a)microsoft.com...
> How do I create a macro that will delete entire row if older then 365
> days.
> Dates are on col "A"
> last col of data = "U"
> Data is kept in sheet "details"
>
> Thank you