Error with IF/OR in VBA

*爱你&永不变心* 提交于 2020-01-06 08:04:19

问题


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

I am using this formula in VBA but it is not working. Syntax looks fine.


回答1:


Too many ")"

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



回答2:


In general, try the following:

  • Make a workable formula in Excel
  • Then select the cell with the workable formula
  • Run the following code

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

  • In the immediate window something useful should be printed.

Source: Apply formula in VBA?



来源:https://stackoverflow.com/questions/45441679/error-with-if-or-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!