2017-08-01 65 views
0
.Range("BS2:BS" & NewLastRow).Formula = "=IF((OR(BR2=""FLAG"",BO2>0)),""FLAG"",""NOFLAG""))" 

我在VBA中使用此公式,但它不起作用。語法看起來很好。與VBA中的IF/OR錯誤

回答

3

太多 「)」

.Range("BS2:BS" & NewLastRow).Formula = "=IF(OR(BR2=""FLAG"",BO2>0),""FLAG"",""NOFLAG"")" 
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?