Excel VBAsearchdate范围并删除旧条目

我需要一个macros,它将search整个完成date列,并在完成date过去90天后删除相应的数据行。 这是我迄今为止。

Dim RowDate Dim CurrentDate Dim Interval Dim CurrentAddress Dim ValueCellRange As Range Dim ValueCell As Range 'Interval set to an appropriate number of days Interval = 90 CurrentDate = Now() 'Identify starting row for sweep Set ValueCellRange = Range("G2:G100") 'Set loop to execute until empty cell is reached For Each ValueCell In ValueCellRange If CurrentDate - ValueCell.Value >= Interval Then ValueCell.EntireRow.ClearContents End If Next ValueCell 'Clear variable value for next initialization Set ValueCell = Nothing 

如果你只是想跳过空白在循环中添加另一个if语句

通过工作表编辑添加的循环

 Dim ws as Worksheet For Each ws in Worksheets Set ValueCellRange = ws.Range("G2:G100") For Each ValueCell In ValueCellRange If ValueCell.Value <> "" Then If CurrentDate - ValueCell.Value >= Interval Then ValueCell.EntireRow.ClearContents End If End If Next ValueCell Next ws