ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Number format in vba (https://www.excelbanter.com/excel-programming/289819-number-format-vba.html)

gregork

Number format in vba
 
I have the following code for passing some data on to a user form:

Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Value

End Sub

Works fine except for one thing - I am getting a number in my text box that
has 12 decimal places.
How do I format so the value returned only has 2 decimals?

Regards
gregork



Joseph[_11_]

Number format in vba
 
Hi gregork,

What kind of data is in A7

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Number format in vba
 
You could control the format explicitly, like:

Me.TextBox1.Value = format(Sheets("Blend Sheet").Range("ac7").Value,"0.00")

or you could pick up what's displayed in the worksheet:

Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Text



gregork wrote:

I have the following code for passing some data on to a user form:

Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Value

End Sub

Works fine except for one thing - I am getting a number in my text box that
has 12 decimal places.
How do I format so the value returned only has 2 decimals?

Regards
gregork


--

Dave Peterson


JE McGimpsey[_2_]

Number format in vba
 
one way:

Me.TextBox1.Value = Format(Sheets("Blend Sheet").Range("ac7").Value, _
"0.00")


In article ,
"gregork" wrote:

I have the following code for passing some data on to a user form:

Private Sub UserForm_Initialize()
Me.TextBox1.Value = Sheets("Blend Sheet").Range("ac7").Value

End Sub

Works fine except for one thing - I am getting a number in my text box that
has 12 decimal places.
How do I format so the value returned only has 2 decimals?

Regards
gregork




All times are GMT +1. The time now is 01:13 PM.

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