How does one set the number format in Text Boxes (e.g., % with one decimal point; general number with comma separator without decimals?)
Also can the % symbol be set as a trailing character in the box where the percentages will be entered?
Printable View
How does one set the number format in Text Boxes (e.g., % with one decimal point; general number with comma separator without decimals?)
Also can the % symbol be set as a trailing character in the box where the percentages will be entered?
Hi,
So what kind of text boxes are you dealing with? Is it on a UserForm? From the Controls Toolbox, Forms Toolbox?
They are text boxes on the UserForm itself, using the Controls Toolbox.
Not that I know of. You can add an additional line to your code though, when inserting that value ...
If they enter it as a percent already (e.g. 0.15 is 15%) then take out the " / 100" portion. That is only if they enter 15 as 15%.Code:Private Sub CommandButton2_Click()
[A1].Value = TextBox1.Value / 100
[A1].NumberFormat = "00.0%"
Unload UserForm1
End Sub
Hi,
Is this the sort of thing that you mean?
Code:Private Sub TextBox1_AfterUpdate()
Me.TextBox1.Text = Format(Me.TextBox1.Text, "0.0%")
End Sub
Private Sub TextBox2_AfterUpdate()
Me.TextBox2.Text = Format(Me.TextBox2.Text, "#,##0")
End Sub
HTH
more or less; the % formatting for TextBox 1 works but the comma separated number format for TextBox2 does not
The #,##0 format works, but you need a 4 digit number to get the comma. If you want leading zeros you can use this:
Code:Private Sub TextBox2_AfterUpdate()
Me.TextBox2.Text = Format(Me.TextBox2.Text, "0,000")
End Sub
Could there be a problem with the location of the statements in relation to the the other subs? The formats work fine when first entered in the UserForm but, when the wizard is restarted, the last entered numbers still appear in general number format (e.g., 0.15 and 10000)
You may need to reformat it after the last update. Can you post an attachment of what you are working with and maybe we can help further.
Thanks Jacob. Here is the zipped file. If the purpose of this workbook seems obscure, it is because it is a dry run for inserting data from a multipage form to specific cells in the various worksheets.
Try this line in the initialize sub when the macro starts:
Code:Me.TextBox1.Value = Format(.Worksheets("sheet1").Range("b3").Value, "Percent")