Consulting

Results 1 to 6 of 6

Thread: Round Up the answer to a calculation which is being performed in VB

  1. #1

    Round Up the answer to a calculation which is being performed in VB

    Hi there.

    Within a VB procedure i have a very simple calculation i.e. Number 1 divided by Number 2 = Answer.
    The results returned always have multiple decimal places i.e. 98.827876.

    I would like to pass / insert this value into a Textbox which has been embedded into a Worksheet, but I need it to appear as a % with either 1 or no decimal places.

    I've added the % symbol in the simplest that I know i.e. TextboxText = Answer & "%" but the end result shows as 98.827876% (I need to lose some/all of the decimal places)

    Is it possible to Round Up the "Answer" to the calculation being performed inside the procedure within VB ?

    or

    Can I limit the value which is being passed to the embedded textbox so that the end result is simply 98.8% or 99% ?

    Hope this makes sense.

    Any help would be greatly appreciated.

  2. #2
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    18
    Location
    Hi Mark,

    round function will do what you are looking for.

    TextboxText = Round(Answer,2)

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,669
    Location
    'RoundUp' or just 'Round'?

    TextBox1.Text = Format(.9849, "0#.0%")
    Capture.JPG
    Last edited by Paul_Hossler; 02-26-2021 at 03:28 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Quote Originally Posted by arangogs View Post
    Hi Mark,

    round function will do what you are looking for.

    TextboxText = Round(Answer,2)
    Brilliant. Thank you. and so simple too.

  5. #5
    ignore

  6. #6
    Quote Originally Posted by Paul_Hossler View Post
    'RoundUp' or just 'Round'?

    TextBox1.Text = Format(.9849, "0#.0%")
    Capture.JPG
    Thank you

Posting Permissions

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