Hi guys,
I need help deleting rows which contain a cell with date / time in the format dd/mm/yyyy hh:mm if the value is older than the current date / time
any ideas?
thanks
Last edited by mattmac; 04-01-2009 at 12:10 PM.
More info please...
Where are the dates located (range-wise) ?
Are the date time values listed in any sort of order ?
Is the Current Date always listed ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Sorry,
dates are in column S and there could be any number of rows.
dates are in format dd/mm/yyyy hh:mm (all in one column) and they have not been soretd.
The current date / time isn't listed, I just want to pull that from the system clock.
Thanks
One way.. possibly...
Assumes S1 is a header value and first datetime value appears in S2Code:Sub PurgeOld() Dim rngData As Range Set rngData = Range(Cells(1, "S"), Cells(Rows.Count, "S").End(xlUp)) With rngData .AutoFilter Field:=1, Criteria1:="<" & CDbl(Now) .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete .AutoFilter End With Set rngData = Nothing End Sub
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Acutally i'm getting an error:
runtime error 1004
autofilter method of range class failed
at this bit:
.AutoFilter Field:=1, Criteria1:="<" & CDbl(Now)
Last edited by mattmac; 04-01-2009 at 11:22 AM.
Hi,
Try this :
Regards,Code:Sub checkfordate() Dim counter As Long Dim i As Long Dim rownum As Long counter = 0 rownum = ActiveSheet.UsedRange.Rows.count - 1 + ActiveSheet.UsedRange.Rows(1).Row For i = rownum To 1 Step -1 If Cells(i, 19) < Now Then Rows(i).Delete End If counter = counter + 1 Next i End Sub
Shekar.
Ahh thats it cheers!!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks