Search code examples
excelvbaexcel-formulatextbox

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.


Solution

  • Use IIf:

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