我尝试在 excel VBA 中使用常用的 less 运算符给出一个值。因此,每当一个单元格中的值小于 8 且大于 0 时,我想给出值 18。否则将打印出“空”。这仅适用于某些列不为空的特定行。这是我的代码片段:
ActiveWorkbook.Sheets(1).Columns(22).NumberFormat = "0.00"
ActiveWorkbook.Sheets(1).Columns(23).NumberFormat = "0.00"
For x = 2 To LastRow
If Not IsEmpty(Cells(x, "E")) And Not IsEmpty(Cells(x, "F")) And Not IsEmpty(Cells(x, "G")) And Not IsEmpty(Cells(x, "H")) And Not IsEmpty(Cells(x, "I")) And Not IsEmpty(Cells(x, "J")) Then
If Cells(x, "V").Value <= "8" And Cells(x, "V").Value > "0" Then
Cells(x, "AA").Value = "18"
Else: Cells(x, "AA").Value = "Empty"
End If
End If
Next x
该代码仅适用于值为 9 的单元格,除此之外它总是给出 18,即使该数字远高于 8。
我还检查了调试器,它说 Value/Double 作为类型和单元格的正确值。但无论如何宏进入 18.