使用VBA基于一列中的时间和另一列中的值删除行

我试图创build一个代码,如果列B有“7:00”和列G有“0”,将删除一行。 我一直在搞下面的代码,看来代码将不会识别B列(格式为h:mm)中的“7:00”,除非我input为“7:00”。 这是否与时间值的格式有关? 有没有更好的方法来完成这个?

我一直在尝试的代码:

Dim N As Long, i As Long N = Cells(Rows.Count, "B").End(xlUp).Row For i = N To 1 Step -1 If Cells(i, "B") = "7:00" And Cells(i, "G") = "0" Then Cells(i, "B").EntireRow.Delete End If Next i 

这应该适合你。

 If Cells(i, "B").Text = "7:00" And Cells(i, "G").Text = "0" Then Cells(i, "B").EntireRow.Delete End If