Formating values in userform text box to one decimal place

Nick

Board Regular
Joined
Jul 11, 2002
Messages
70
Hi all,

I have the following userform that returns the % change between two numbers:

Private Sub CommandButton1_Click()
On Error Resume Next
answer.Text = (Val(y.Text) - Val(x.Text)) / Val(y.Text) * 100
End Sub

Does anyone know how to ensure that it only displays the answer to one decimal place in the textbox?

Thanks

Nick
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
I've used this before. You just need to tell it to format that textbox specifically:<PRE>Private Sub textbox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

textbox1 = Format(textbox1, "0.0;(0.0)")

End Sub</PRE>

If you want it to show the percent sign as well, just change it to 0.0%. What I have above will format negative numbers as being in parenthesis (that was in my original code, but you can always change that if you need to).
_________________<font color="#3399FF" size="3">Kristy</font>
kitten_smush2.jpg

This message was edited by Von Pookie on 2002-10-22 14:03
This message was edited by Von Pookie on 2002-10-22 14:04
 

Forum statistics

Threads
1,144,124
Messages
5,722,626
Members
422,448
Latest member
AugyIA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top