• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Userform Calculations

tome10

New Member
How do I enter numbers in Textbox1 (4.33mi), and Textbox 2 shows the calculated result in (km) ? I borrowed the key down from somewhere else, is this a proper use for it?

Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
TextBox2.Value = CONCATENATE(Round(Left(TextBox1.Value, 4) * 1.609, 2), "km")
End Sub
 
If it works for you, then it is proper.

Having said that ... there are usually several different methods to accomplish your goals using Excel. If a challenge has
3 different methods to attain a solution, that doesn't make two of those "bad".
 
I agree with Logit ("if it works, then great!"), but I am looking askance at TextBox1_KeyDown. Doesn't that trigger when the user presses any single key? And the function Left(TextBox1.Value, 4) tells me the user may have to enter up to four chars in that box before TextBox2 can show anything meaningful. So mightn't it be better to use a different event? It might take some experimentation to find the best one, but maybe TextBox1_Exit (when TextBox1 loses the focus), or TextBox2_Enter (when the operator tabs to TextBox2), or TextBox1_AfterUpdate (when VBA knows in some way that the user has finished entering data). Or I think you could use KeyDown but first check to be sure it's the <Enter> key the user pressed; that way it doesn't interrupt while he's still typing numerals.
 
Back
Top