Userform Textbox Format Problem

  • Thread starter Thread starter jeffcadle78
  • Start date Start date
J

jeffcadle78

I'm having a problem with the formatting of a textbox on a userform.
Basically, I have the text box linked to a cell that shows a
percentage.

However the text box shows the value in the "Scientific" format.

Is there a way that I can make the text box show the value exactly as I
have it in my workbook?

If not, is there a way to format it so that it appears the way I want
it to appear?


Any help will be greatly appreciated.
Thanks in advance.
 
Maybe you could just drop the linked cell (called the controlsource in a
userform) and do it via code.


Either have it update when you're typing (use the _change code):
Option Explicit
Private Sub TextBox1_Change()
Worksheets("Sheet1").Range("A1").Value = "'" & Me.TextBox1.Text
End Sub

or when you leave the textbox:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Worksheets("Sheet1").Range("A1").Value = "'" & Me.TextBox1.Text
End Sub

The bad news is getting the format correct. If you know what it's supposed to
be, you can do the format yourself:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Worksheets("sheet1").Range("a1")
.Value = CDbl(Me.TextBox1.Value)
.NumberFormat = "0.00%"
End With
End Sub

The apostrophe's in the first example will make the value in A1 text. The value
will look exactly like what's typed in the textbox, but you'll have to do other
stuff to treat it as numeric! (I wouldn't use those versions.)

If you have your code put a value into a cell, it's like typing it in manually.
The cell's numberformat will take hold and it might not be what you typed.
 
Back
Top