Patrick
Patrick

Reputation: 232

Using TextBox to insert formula

I’m hoping someone could help me with this coding.

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

I want the active cells formula to look something like =Z_End or =Z_Origin.

Upvotes: 0

Views: 62

Answers (2)

JMP
JMP

Reputation: 4467

Use IIf:

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

Upvotes: 1

simple-solution
simple-solution

Reputation: 1139

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

Upvotes: 0

Related Questions