ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm TextBox Decimal Places (https://www.excelbanter.com/excel-programming/286746-userform-textbox-decimal-places.html)

pcsis

UserForm TextBox Decimal Places
 
Hi All,

I've got a UserForm with TextBoxes that when opened fill the TextBoxes with
numerical values form specific worksheet cells.
If the Range value has a number like 4.67, this shows up in the textbox no
problem, but when the range value is 4.00 it appears as 4.
I would like the textboxes show a minimum of two decimal places. Any
assistance would be greatly appreciated.

Private Sub UserForm_Initialize()
TextBox1.Value = Range("C7").Value
TextBox2.Value = Range("C8").Value
TextBox3.Value = Range("C9").Value
TextBox4.Value = Range("C10").Value
End Sub

Best regards,
Pete



Daniel Klann

UserForm TextBox Decimal Places
 
Pete,

You can use the Format method e.g.

Private Sub UserForm_Initialize()
TextBox1.Value = Format(Range("C7").Value, "0.00")
TextBox2.Value = Format(Range("C8").Value, "0.00")
TextBox3.Value = Format(Range("C9").Value, "0.00")
TextBox4.Value = Format(Range("C10").Value, "0.00")
End Sub

Regards,
Dan
-----------------------------------------
Website : http://www.danielklann.com
Favourites Add-in for Microsoft Excel -
http://www.danielklann.com/excel/exc...tes_add-in.htm


"pcsis" wrote in message
news:VpsJb.139284$ss5.40484@clgrps13...
Hi All,

I've got a UserForm with TextBoxes that when opened fill the TextBoxes

with
numerical values form specific worksheet cells.
If the Range value has a number like 4.67, this shows up in the textbox no
problem, but when the range value is 4.00 it appears as 4.
I would like the textboxes show a minimum of two decimal places. Any
assistance would be greatly appreciated.

Private Sub UserForm_Initialize()
TextBox1.Value = Range("C7").Value
TextBox2.Value = Range("C8").Value
TextBox3.Value = Range("C9").Value
TextBox4.Value = Range("C10").Value
End Sub

Best regards,
Pete





Tom Ogilvy

UserForm TextBox Decimal Places
 
Just to add, if you want them to appear as the cells do:

Private Sub UserForm_Initialize()
TextBox1.Value = Range("C7").Text
TextBox2.Value = Range("C8").Text
TextBox3.Value = Range("C9").Text
TextBox4.Value = Range("C10").Text
End Sub

--
Regards,
Tom Ogilvy

pcsis wrote in message
news:VpsJb.139284$ss5.40484@clgrps13...
Hi All,

I've got a UserForm with TextBoxes that when opened fill the TextBoxes

with
numerical values form specific worksheet cells.
If the Range value has a number like 4.67, this shows up in the textbox no
problem, but when the range value is 4.00 it appears as 4.
I would like the textboxes show a minimum of two decimal places. Any
assistance would be greatly appreciated.

Private Sub UserForm_Initialize()
TextBox1.Value = Range("C7").Value
TextBox2.Value = Range("C8").Value
TextBox3.Value = Range("C9").Value
TextBox4.Value = Range("C10").Value
End Sub

Best regards,
Pete






All times are GMT +1. The time now is 09:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com