Consulting

Results 1 to 11 of 11

Thread: Solved: Textbox Format Value

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Solved: Textbox Format Value

    How can I display the textbox value in "%" format?

    [vba]
    .TextBox1.Value = c.Offset(0, 28).Value
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I believe it's something like this used in the Sub tetxbox1_change:
    [vba]
    Me.TextBox1.Value = Format(Textbox1.Value, "%")
    [/vba]where Me will be the object it resides in, if you are using it in code not in the object module you need to specify the object i.e Userform1.TextBox1.....etc

    Regards
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    To change 15 to 15.00%

    [VBA]Me.TextBox1.Value = Format(TextBox1.Value / 100, "0.00%")[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    LOL i was close!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Save data in the worksheet using TextBox1 (Perfect Code). Thanks "mdmackillop" for this code. It makes the user entry more easier.
    [vba]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox1.Value = Format(TextBox1.Value / 100, "0.0%")
    End Sub
    [/vba]

    But when I call back the data in the worksheet using TextBox1, 10% becomes 0.1 in the textbox happens when I used below code.

    Call data from the worksheet using TextBox1
    [vba]
    .TextBox1.Value = c.Offset(0, 28).Value
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA].TextBox1.Value = Format(c.Offset(0, 28).Value ,"0.0%)[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    mdmackillop Perfect. Thanks

    Quote Originally Posted by mdmackillop
    [vba].TextBox1.Value = Format(c.Offset(0, 28).Value ,"0.0%)[/vba]
    What about passing a null value with this code...
    [VBA]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox1.Value = Format(TextBox1.Value / 100, "0.0%")
    End Sub
    [/VBA]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use the text property [vba] .TextBox1.Value = c.Offset(0, 28).Text [/vba]

  9. #9
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    I have this code in the textbox. When I skip the textbox1 error come which is data type mismatch that made me into conclusion that skipping the textbox1 is not permitted. What I want to happen is a code if it's possible to skip textbox1 and entry to be made in textbox2.

    [vba]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox1.Value = Format(TextBox1.Value / 100, "0.0%")
    End Sub [/vba]

    [vba]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox2.Value = Format(TextBox2.Value / 100, "0.0%")
    End Sub
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.TextBox1
    If .Value = "" Then
    .Value = 0
    End If
    .Value = Format(.Value / 100, "0.0%")
    End With
    End Sub
    [/vba]

  11. #11
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    xld ... this code works perfectly... once again thanks.

    Quote Originally Posted by xld
    [vba]
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.TextBox1
    If .Value = "" Then
    .Value = 0
    End If
    .Value = Format(.Value / 100, "0.0%")
    End With
    End Sub
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

Posting Permissions

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