我在 excel 上有一个 csv 文件,它是列的 ~CU。
并且该行不断更新(截至目前为 2606)。
我试着
before today's date
的行记录在 D 列 Sub deleterows()
lastrow = Cells(Rows.Count, 4).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 4).Value < *numeric value* Then Rows(i).EntireRow.Delete
Next i
End Sub
最佳答案
对于日期(和货币),始终建议使用 Value2
而不是 Value
.
MSDN:
The only difference between this property and the Value property is that the Value2 property doesn’t use the Currency and Date data types. You can return values formatted with these data types as floating-point numbers by using the Double data type.
所以你需要做的就是改变这部分
If Cells(i, 4).Value < *numeric value* Then
有了这个
If Cells(i, 4).Value2 < Date Then
如果 D 列比今天更旧,它评估为真。
关于VBA 删除今天日期之前的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41470034/