【问题标题】:How can I check if a value is 0 in Excel? (If there are blank cells in the same column)如何检查Excel中的值是否为0? (如果同一列中有空白单元格)
【发布时间】:2023-01-14 09:43:07
【问题描述】:

我在 Excel 上有一个表格,B 列包含数字(从 0 到 240),但它也包含空白。

我有一个看起来像这样的代码

for i = 2 to 500

My_Value = Worksheets("MachineData").range("B" & i).value

if My_Value = 0 then
'Do Something
end if

next i

问题在于 Excel 认为空白单元格也是 0。那么如何检查单元格的值何时为 0 且仅为 0?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    我相信您应该检查该值是否为零,并结合该值的长度是否为一。 (长度为零表示什么都不填)

    在代码中:(未测试)

    if ((My_Value = 0) And Len(My_Value) = 1) then then
    

    【讨论】:

      猜你喜欢
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      相关资源
      最近更新 更多