VBA Delete Excel Rows Based on Certain Date
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
- Microsoft Excel 2003/2007 Video Tutorials
Step-by-step video guide to mastering Charts, PivotTable, Data Analysis and Macro programming in Microsoft Excel in 5 hours.
- 101 Secrets of Microsoft Excel
Discover 101 of Excels little-known secrets that have been hiding right under your nose.
Tagged with: columns, delete row, excel macro, filtered date, function cells, vba delete excel row
garbo7441
This macro will delete all rows that contain a date before August 1, 2008.
Q1 2009 Wrap up - Code For Excel And Outlook Blog
[...] Poer from ExcelVBAMacro — see his latest post Delete Rows based on certain date [...]
Q1 2009 Wrap up
[...] Poer from ExcelVBAMacro — see his latest post Delete Rows based on certain date [...]
Xavier
It returns a run-time error 1004, plz help