我正在处理一个列表,如果满足两个条件,则需要自动清除G-I列中的数据:
AND
我一直在使用Google搜索和阅读,使用If DateDiff
代码发现了一些我认为正确的东西,但是我不知道如何调整代码以匹配每行和还应考虑需要填写N列。
Sub Workbook_Open()
If Not Intersect(Target, Range("N6:N2000")) Is Nothing Then
If DateDiff("d", FileDateTime(ThisWorkbook.FullName), Now) >= 120 Then
' this above needs to only check on cell at the time in A???
Target.Offset(0, -5).ClearContents
Target.Offset(0, -6).ClearContents
Target.Offset(0, -7).ClearContents
ThisWorkbook.Save
End If
End If
End Sub
我要靠近吗?
答案 0 :(得分:0)
最终找到了解决方案:
Sub ClearCells()
Dim Cel As Range, Ws As Worksheet
Set Ws = Sheets("NameOfSheet")
For Each Cel In Ws.Range("A6", Ws.Range("A" & Rows.Count).End(xlUp))
If DateDiff("d", Cel, Date) > 120 And Cel.Offset(, 13) <> "" Then
Cel.Offset(, 6).Resize(, 3).ClearContents
Next Cel
End Sub