VBA在今天的date之前删除行
我有一个csv文件在Excel中是〜CU的列。
行得到更新(截至目前为2606)。
我试图
- 删除列D上logging的
before today's date
所有行 - 今天的date没有打字/文本框/人的input。
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
对于date(和货币),总是build议使用Value2
而不是Value
。
MSDN:
此属性和Value属性之间的唯一区别是Value2属性不使用货币和date数据types。 您可以使用Double数据types将使用这些数据types格式化的值作为浮点数返回。
所以你所要做的就是改变这个部分If Cells(i, 4).Value < *numeric value* Then
用这个If Cells(i, 4).Value2 < Date Then
如果D列比今天更早,则评估为真。