您好,提前感谢您能提供的任何建议。我已经写了下面的VBA代码,不能让它识别时间>= 20分钟,或<20分钟。基本上,我要做的是将两个时间值相减,得到一个单元格的差值,然后突出显示任何单元格>= 20分钟黄色,<20分钟红色。我已经将代码设置为向下迭代行,所以不确定这是否是问题所在。请参阅下面的代码。
Sub Calculations()
Dim i As Integer
i = 2
Do While Cells(i, 1) <> ""
Cells(i, 7).Value = Cells(i, 2).Value - Cells(i, 1).Value
If Cells(i, 7).Value >= 0.0138 Then
Cells(i, 7).Font.ColorIndex = True
Cells(i, 7).Font.ColorIndex = 3
ElseIf Cells(i, 7).Value < 0.0138 Then
Cells(i, 7).Font.ColorIndex = 1
Cells(i, 7).Interior.ColorIndex = 27
i = i + 1
End If
Loop
End Sub到目前为止,它只向下计算到某一行,然后锁定,给我一个运行时错误"ColorIndex“的Object not found。我试着用0.0138来代表20分钟,但还是没有成功。注意:当我输入一个值"20“时,它会计算所有的差异,但当然也会突出显示所有黄色的内容。感谢您能提供的任何建议。
发布于 2018-09-08 00:11:47
仅当差异小于20分钟时,您的循环才会增加i。将i = i + 1移出If ...ElseIf ...结束If。
Do While Cells(i, 1) <> ""
Cells(i, 7).Value = Cells(i, 2).Value - Cells(i, 1).Value
If Cells(i, 7).Value >= timeserial(0, 20, 0) Then
Cells(i, 7).Font.Bold = True
Cells(i, 7).Font.ColorIndex = 3
ElseIf Cells(i, 7).Value < timeserial(0, 20, 0) Then
Cells(i, 7).Font.ColorIndex = 1
Cells(i, 7).Interior.ColorIndex = 27
End If
i = i + 1
Loophttps://stackoverflow.com/questions/52226132
复制相似问题