有沒有辦法檢查活動單元格的特定公式?這是我運行的一個簡單的測試,不斷返回「否」。VBA/Excel宏 - 如何檢查單元的特定公式
sub Test
'Add formula to a Cell
Range("J3").Select
ActiveCell.FormulaR1C1 = "=R[-1]C+RC[-2]-RC[-1]"
If (ActiveCell.Formula = "=R[-1]C+RC[-2]-RC[-1]") Then
MsgBox ("Yes")
Else
MsgBox ("No")
End If
End Sub
* 更新 * 這是我的工作了。
Sub Test()
'Add formula to a Cell
Range("J3").Select
ActiveCell.FormulaR1C1 = "=R[-1]C+RC[-2]-RC[-1]"
'Convert Formula in the Cell to a string
Dim strFormula As String
strFormula = ActiveCell.FormulaR1C1
If (strFormula = "=R[-1]C+RC[-2]-RC[-1]") Then
MsgBox ("Yes")
Else
MsgBox ("No")
End If
End Sub
您更新的代碼沒有任何意義。請在我的回答下查看我的評論。 –
當然,你的'.formula'永遠不會像'r [] c []'樣式。 –
是的,你一直都是對的。我使用.formula代替.formulaR1C1的錯誤:-) – Ollie