有没有办法检查活动单元格的特定公式?这是我运行的一个简单的测试,不断返回“否”。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