MrExcel Consulting
Your One Stop for Excel Tips & Solutions

Format Textbox


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

Hello,

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, "###%")
FormatNumber(YourNum)
FormatPercent(YourPer

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.


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

Hi,

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