Archive of Mr Excel Message Board

Back to Links in Excel archive index
Back to archive home

Format Textbox

Posted by Dave on October 18, 2001 9:17 AM

Someone please help.

I have a textbox on a userform that is linked to a cell (control sourc)e.
The linked data are numbers like (1,700,000 or 33%) the problem is
the textbox shows the numbers as 1700000 and .333333333 How can I
format the result in the textbox?

. I put this code(s) in
the userform code like this

Private Sub TextBox1_Change()

yourTextBox.text = Formatnumber(Linked Data,[#,##0])

End Sub

here are some other variations.

yourTextBox.Text = FormatNumber("#,##0")
yourTextBox.text = Formatnumber(Linked Data,[#,##0])
FormatNumber ("$#,##0.00_);[Red]($#,##0.00)")
format(YourNumber, "###,###,##0.00")
format(YourPercentage, "###%")

The problem is this are not working and when I have the code in
Private Sub TextBox1_Change()the textbox which is linked gives me a
compile error if I try to edit the textbox on the user form?

Help I'm stuck Thanks in advance again.

Re: Format Textbox

Posted by Juan Pablo on October 18, 2001 9:32 AM

I have had a lot of problems with the linking cell, because Excel passes it as "General", what i do is instead of having a linked cell, i use either the UserForm_Initialize() event or whatever works for you and put something like

TextBox1 = Worksheetfunction.Text(Range("A1"),"0.00%")

And that way you get it in the "right" format, or at least in the one you want.

Juan Pablo

This archive is from the original message board at
All contents © 1998-2004
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.