+ Reply to Thread
Results 1 to 3 of 3

Calculation based on input from userform textbox

  1. #1
    Registered User
    Join Date
    05-07-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2007
    Posts
    42

    Question Calculation based on input from userform textbox

    Hi guys

    I have an userform with a textbox. Based on the input I would like to make some calculations (the input has to be a number). How can I do this? I think that I have to change the input from text to a number, but I don't know how. I hope some of you guys can help me out Thx a lot in advance!

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Calculation based on input from userform textbox

    Here is a way to enforce numeric input into a text box.
    Any other character will not appear in the text box; it will
    be removed by the code after it is typed.
    Please Login or Register  to view this content.
    This is how you might convert the text box value for use in a numeric calculation.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Calculation based on input from userform textbox

    This will prevent the user from entering anything other than a non-negative integer.
    Please Login or Register  to view this content.
    If you want the user to be able to enter any number, you could use this kind of code.
    Please Login or Register  to view this content.
    The BeforeUpdate event is to change the text that the user enters into a standard format.
    This code will force a "general" format, so that if either "1.23000" or "123e-02" is entered, they will both be shown as "1.23" (after the focus leaves the textbox).
    You could change that to any format that you prefer.

    Note that the BeforeUpdate event uses the Val function to convert a string into a number.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1