Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Format a TextBox on a Userform to 2 decimal places

  1. #1
    Board Regular berty2000's Avatar
    Join Date
    Mar 2011
    Location
    Kent UK
    Posts
    69
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Format a TextBox on a Userform to 2 decimal places

    Hi Guys,

    Could you be so kind as to provide some code that will enable me to display a text box on a userform rounded up to 1 decimal place.

    Where am I going wrong....
    it calculates the number entered in textbox1 and divides it by a value that changes in cell O26 but the answer is in about 8 or more decimel places.
    Only need like 65.3 as an answer not 65.277756942

    This is the code ive used.

    Private Sub CommandButton1_Click()

    TextBox2.Value = Val(TextBox1.Value) / Range("O26").Value

    End Sub

  2. #2
    Board Regular
    Join Date
    Sep 2009
    Location
    Egypt
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    try this

    Code:
    Private Sub CommandButton1_Click()
     
    TextBox2.Value = format(Val(TextBox1.Value) / Range("O26").Value,"0,00")
     
    End Sub

  3. #3
    Board Regular berty2000's Avatar
    Join Date
    Mar 2011
    Location
    Kent UK
    Posts
    69
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    Excellent nearly there
    the sum I enter is 6500 / 72 = 90.27777
    Would like it to round up if possible and display 90.3

    At the min when calculate with your code it reads 090

    Is there a roundup code

  4. #4
    Board Regular berty2000's Avatar
    Join Date
    Mar 2011
    Location
    Kent UK
    Posts
    69
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    Quote Originally Posted by thunder_anger View Post
    try this

    Code:
    Private Sub CommandButton1_Click()
     
    TextBox2.Value = format(Val(TextBox1.Value) / Range("O26").Value,"0,00")
     
    End Sub
    Excellent nearly there
    the sum I enter is 6500 / 72 = 90.27777
    Would like it to round up if possible and display 90.3

    At the min when calculate with your code it reads 090

    Is there a roundup code

  5. #5

    Join Date
    Feb 2003
    Location
    Gurgaon/Thrissur
    Posts
    2,615
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    Hi,

    try

    Code:
    TextBox2.Value = Application.Round(Val(TextBox1.Value) / Range("o26"), 1)
    HTH

  6. #6
    Board Regular berty2000's Avatar
    Join Date
    Mar 2011
    Location
    Kent UK
    Posts
    69
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Re: Format a TextBox on a Userform to 2 decimal places

    That is perfect just what I was after.
    Thank You Very Much

  7. #7
    Board Regular PoggiPJ's Avatar
    Join Date
    Mar 2008
    Location
    Maryland, USA
    Posts
    330
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    How could you modify that format statement so that the UserForm will always display properly regardless of the user's country settings? For example, if that same form were in the US, the comma would need to be a decimal?
    Last edited by PoggiPJ; Aug 11th, 2011 at 02:33 PM.
    Regards,
    Peter Poggi
    North Potomac, MD
    USA

  8. #8
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    2,916
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    Use concatenation for that character:
    Code:
    application.DecimalSeparator

  9. #9
    Board Regular PoggiPJ's Avatar
    Join Date
    Mar 2008
    Location
    Maryland, USA
    Posts
    330
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    could you please put that into context? All users, worldwide, will use the same application. There will not be a separate app for each country, so I do not know how to format it prior to the UserForm display
    Regards,
    Peter Poggi
    North Potomac, MD
    USA

  10. #10
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    2,916
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Format a TextBox on a Userform to 2 decimal places

    Code:
    Private Sub CommandButton1_Click()
      TextBox2.Value = Format(Round(TextBox1.Value / Range("O26").Value, 2), "0" & Application.DecimalSeparator & "00")
    End Sub

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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