【发布时间】:2018-07-26 18:57:06
【问题描述】:
因此,如果 B 列在 2018 年(2018 年 1 月 1 日)之前或 D 列小于 1,则应删除整行,问题是我的代码正在运行但未满。它不会删除所有符合条件的行,它只会删除一些符合条件的行。
我的代码也是
Dim wks As Worksheet
Dim i As Long
Dim LastRow Aqs Long
Dim PODate As Date
Dim THDate As Date
Worksheets("testPO").Activate
Set wks = ActiveSheet
LastRow = wks.Cells(wks.Rows.Count, "A").End(xlUp).Row
Cells(LastRow, "A").Activate
For i = 8 To LastRow
If Cells(i, "D").Value < 1 Or Cells(i, "B") < 43101 Then
Rows(i).Select
Selection.Delete Shift:=xlUp
End If
Next i
End Sub
【问题讨论】:
-
简短回答:向后循环而不是向前循环。
For i = LastRow to 8 Step -1
标签: vba excel date-comparison