Calculate Field in UserForm on Exit

  • Thread starter Thread starter Orion Cochrane
  • Start date Start date
O

Orion Cochrane

I have a userform that is used to enter different data, and sometimes I have
to enter a formula in the textbox. Is there a way, using my existing
txtField_Exit events to calculate the value if I enter something like "=2+2"
and it gives me the answer when I tab away from the active textbox?
 
Hi,

How about this

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MySum = Evaluate(TextBox1.Text)
End Sub

Mike
 
Thanks. I tried a variation that worked:
txtField.Value = Evaluate(txtField.text)
This helped me immensly!
 
Glad I could help and thanks for the feedback. I shpuld have pointed out you
could populate the textbox with the answer.

You could also populate another textbox with the answer.

If you do this then you should consider error trapping because if you enter
something that can't be evaluated you will get an error.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox1.Text = Evaluate(TextBox1.Text)
End Sub

Mike

Mike
 
Back
Top