Macro - delete rows based on date

前端 未结 4 1695
北恋
北恋 2020-12-17 07:36

I am very new to VBA and macros in Excel. I have a very large excel spreadsheet in which column A holds dates. I am trying to delete the rows which have a value smaller than

4条回答
  •  生来不讨喜
    2020-12-17 07:53

    You have an additional Next i for some reason in your code as highlighted by the debugger. Try the below:

    Sub DELETEDATE()
    Dim x As Long
    For x = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
    Debug.Print Cells(x, "A").Value
    If CDate(Cells(x, "A")) < CDate("01/01/2013") Then
    Cells(i, "A").EntireRow.Delete
    End If
    Next x
    End Sub
    

提交回复
热议问题