VBA Delete Excel Rows Based on Certain Date

Posted on the January 31st, 2009 under Cells and Range, Workbook and Worksheet by Poer @ Excel VBA/Macro

Let say I have a bunch of formatted data in my Excel sheet, and in Column A I have a dates. Then I wanna filter all the data base on certain date, for example 1 Jan 2009, and delete all others data before that date.

The algorithm is like this: I’ll create a loop from the first row until the last row with data and check if the date is before Jan 1st, 2009 or not, if it is, simply delete that row.

Sub DeleteFilteredRows()
    Dim i As Long

    For i = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
        Debug.Print Cells(i, "A").Value
        If CDate(Cells(i, "A")) < CDate("1/jan/2009") Then
            Cells(i, "A").EntireRow.Delete
        End If
    Next i

End Sub

Of course I’ll make an adjustment to the code above to meet my current condition.

FIN.

Related Entries

External Resources

Tagged with:

4 Responses to 'VBA Delete Excel Rows Based on Certain Date'

  1. February 4, 2009 at 4:54 am
    garbo7441
  2. April 11, 2009 at 5:36 pm
    Q1 2009 Wrap up
  3. September 8, 2009 at 5:27 pm
    Xavier

Leave a Reply




XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
SYNTAX HIGHLIGHTER:
Place your VBA code between <pre> tags like this <pre class="brush:vb"> sub vba() ... end sub </pre>.