make a simple multiplication in a textbox on a userform

  • hi,


    would it be possible to make a multiplication directly in a text box on userform? For example if I type 17*60 and then enter or tab to go to the next text box it is transformed in 1020?


    Thanks,
    Tom.

  • Re: make a simple multiplication in a textbox on a userform


    No this would not work- Excel UserForms' textboxes are truly textboxes so the UserForm would treat that as a string of "17*60" unless you added special formatting to the change event.

  • Re: make a simple multiplication in a textbox on a userform


    One way to "trick" the Textbox into being an inline calculator is to copy the value of the textbox to an unused cell on the underlying worksheet and use Excel itself to calculate the value.


    This can be done a number of ways using the Textbox Exit handler. Here is an example of one way to do this:




    The advantage of this is Excel does all the hard work of determining if the value is a valid calculation.
    There is a disadvantage if you want multiplication to be the *only* form of calculation you will accept. A lot more parsing of the text would be required before letting Excel calculate it.


    This is one method that will work with any valid calculation that you can put into Excel including complex mathematical formulas (assuming the Textbox 'formula' the user types will fit within any MaxLength value you have set for the Textbox).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!