+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    delete rows containing old dates/times

    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.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: delete rows containing old dates/times

    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 ?

  3. #3
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: delete rows containing old dates/times

    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

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: delete rows containing old dates/times

    One way.. possibly...

    Code:
    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
    Assumes S1 is a header value and first datetime value appears in S2

  5. #5
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: delete rows containing old dates/times

    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.

  6. #6
    Forum Contributor
    Join Date
    09-18-2008
    Location
    india
    Posts
    157

    Re: delete rows containing old dates/times

    Hi,

    Try this :

    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
    Regards,
    Shekar.

  7. #7
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Re: delete rows containing old dates/times

    Ahh thats it cheers!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0