【问题标题】:I have problems on executing a If statement in Excel VBA [duplicate]我在 Excel VBA 中执行 If 语句时遇到问题 [重复]
【发布时间】:2019-09-23 09:09:33
【问题描述】:

我在下面的代码中遇到语法错误,请尽快帮助我

谢谢

Set rng = Range("AM4:AM" & Lastrow)
rng.Formula = "=IF(P4="Y",1,0)"  //I need to execute this statement// 

I have attached the screen shot of the error message with the whole code

【问题讨论】:

    标签: excel vba excel-formula windows-10 ms-office


    【解决方案1】:

    请尝试在 Y 周围使用两个双引号:

    rng.Formula = "=IF(P4=""Y"",1,0)"
    

    如果你想在字符串中包含(双)引号,你需要这样做,否则看起来你正在结束字符串,然后 VBA 在到达 Y 时会感到困惑

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多