gpt4 book ai didi

vba - Excel VBA 搜索日期范围并删除旧条目

转载 作者:行者123 更新时间:2023-12-04 20:35:33 24 4
gpt4 key购买 nike

我需要一个宏来搜索整个完成日期列,如果自完成日期起 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

关于vba - Excel VBA 搜索日期范围并删除旧条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43190086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com