ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calculate Field in UserForm on Exit (https://www.excelbanter.com/excel-programming/433106-calculate-field-userform-exit.html)

Orion Cochrane

Calculate Field in UserForm on Exit
 
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?
--
I am running on Office 2003, unless otherwise stated.

Mike H

Calculate Field in UserForm on Exit
 
Hi,

How about this

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

Mike

"Orion Cochrane" wrote:

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?
--
I am running on Office 2003, unless otherwise stated.


Orion Cochrane

Calculate Field in UserForm on Exit
 
Thanks. I tried a variation that worked:
txtField.Value = Evaluate(txtField.text)
This helped me immensly!
--
I am running on Office 2003, unless otherwise stated.


"Mike H" wrote:

Hi,

How about this

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

Mike

"Orion Cochrane" wrote:

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?
--
I am running on Office 2003, unless otherwise stated.


Mike H

Calculate Field in UserForm on Exit
 
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

"Orion Cochrane" wrote:

Thanks. I tried a variation that worked:
txtField.Value = Evaluate(txtField.text)
This helped me immensly!
--
I am running on Office 2003, unless otherwise stated.


"Mike H" wrote:

Hi,

How about this

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

Mike

"Orion Cochrane" wrote:

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?
--
I am running on Office 2003, unless otherwise stated.



All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com