VBA中的IF / OR出错

时间:2017-08-01 15:18:18

标签: excel vba excel-vba

.Range("BS2:BS" & NewLastRow).Formula = "=IF((OR(BR2=""FLAG"",BO2>0)),""FLAG"",""NOFLAG"" ))"

我在VBA中使用此公式,但它不起作用。语法看起来很好。

2 个答案:

答案 0 :(得分:3)

太多“)”

.Range("BS2:BS" & NewLastRow).Formula = "=IF(OR(BR2=""FLAG"",BO2>0),""FLAG"",""NOFLAG"" )"

答案 1 :(得分:2)

一般情况下,请尝试以下方法:

  • 在Excel中制作可行的公式
  • 然后选择具有可行公式的单元格
  • 运行以下代码
Public Sub PrintMeUsefulFormula()

    Dim strFormula  As String
    Dim strParenth  As String

    strParenth = """"

    strFormula = Selection.Formula
    strFormula = Replace(strFormula, """", """""")

    strFormula = strParenth & strFormula & strParenth
    Debug.Print strFormula

End Sub
  • 在即时窗口中,应打印一些有用的东西。

来源: Apply formula in VBA?