Sunday, September 23, 2012

How to Delete Excel Rows Based on Date


1. Open up your workbook in Excel. If you are using Excel 2007, you need to display the 'Developer' tab if it isn't already showing. To do this, click on the 'Office' button and then 'Excel Options.' Click on 'Show Developer Tab' and click 'OK.'
2. Create a new macro. In Excel 2007, click on the Developer tab and then 'Macro.' In earlier versions, click on 'Tools' in the toolbar and then 'Macro.' Name the macro, 'DeleteRowbyDate' and then click 'Create.' The Visual Basic editor appears.
3. Copy and paste the following code into the Visual Basic editor between the lines, Sub DeleteRowbyDate() and End Sub:Dim x As Long
For x = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print Cells(x, 'B').Value
If CDate(Cells(x, 'B'))
Cells(i, 'B').EntireRow.delete
End If
Next iOn the line where it says, ' If CDate(Cells(x, 'B'))
4. Close the Visual Basic editor. It automatically saves to the macro. When you want to run the macro and delete the rows, go back to 'Macros,', select the 'DeleteRowsbyDate' macro and click 'Run.'

Blogger news