使用文本框插入公式

Using TextBox to insert formula

我希望有人能帮助我进行编码。

ActiveCell.Formula = “=“”&IF TextBox3.Value = 1 Then “Z_End” Else “Z_Origin””

我希望活动单元格公式看起来像 =Z_End=Z_Origin

Option Explicit

Private Sub TextBox3_Change()
    MsgBox TextBox3.Value
    If TextBox3.Value = 1 Then
        ActiveCell.Formula = "=Z_End"
    Else
        ActiveCell.Formula = "=Z_Origin"
    End If
End Sub

使用IIf:

 ActiveCell.Formula = IIf(TextBox3.Value = 1, "=Z_End", "=Z_Origin")