ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleteing date over 1 year old (https://www.excelbanter.com/excel-programming/433672-deleteing-date-over-1-year-old.html)

Wolfwalker721

Deleteing date over 1 year old
 
I have a few columns of dates with coresponding numbers in the next column. I
am trying to delete the dates older then one year from Today() and the
coresponding number in the next column. These dates are in order so when it
runs out of dates OR the date is less then one year I would like it to go
over 5 colums and do it again until it runs out of data.

I know most people post the code they are trying to use but in this case I
am looking for a completely fresh perspective.

Any help would be appriciated =)

Thanks!

Simon Lloyd[_1248_]

Deleteing date over 1 year old
 

This should do what you want:

Code:
--------------------
Sub remove_old_dates()
Dim Rng As Range, Mycell As Range
Dim i As Long, ic As Long 'MsgBox ActiveSheet.UsedRange.Columns.Count
Set Rng = ActiveSheet.UsedRange
For ic = 1 To ActiveSheet.UsedRange.Columns.Count Step 5
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Cells(i, ic).Value < Date - 365 Then
Cells(i, ic).EntireRow.Delete
End If
Next i
Next ic
End Sub
--------------------



Wolfwalker721;490100 Wrote:
I have a few columns of dates with coresponding numbers in the next
column. I
am trying to delete the dates older then one year from Today() and the
coresponding number in the next column. These dates are in order so
when it
runs out of dates OR the date is less then one year I would like it to
go
over 5 colums and do it again until it runs out of data.

I know most people post the code they are trying to use but in this
case I
am looking for a completely fresh perspective.

Any help would be appriciated =)

Thanks!



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=135104


Wolfwalker721

Deleteing date over 1 year old
 
THANKS!!

"Simon Lloyd" wrote:


This should do what you want:

Code:
--------------------
Sub remove_old_dates()
Dim Rng As Range, Mycell As Range
Dim i As Long, ic As Long 'MsgBox ActiveSheet.UsedRange.Columns.Count
Set Rng = ActiveSheet.UsedRange
For ic = 1 To ActiveSheet.UsedRange.Columns.Count Step 5
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Cells(i, ic).Value < Date - 365 Then
Cells(i, ic).EntireRow.Delete
End If
Next i
Next ic
End Sub
--------------------



Wolfwalker721;490100 Wrote:
I have a few columns of dates with coresponding numbers in the next
column. I
am trying to delete the dates older then one year from Today() and the
coresponding number in the next column. These dates are in order so
when it
runs out of dates OR the date is less then one year I would like it to
go
over 5 colums and do it again until it runs out of data.

I know most people post the code they are trying to use but in this
case I
am looking for a completely fresh perspective.

Any help would be appriciated =)

Thanks!



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=135104




All times are GMT +1. The time now is 09:42 AM.

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