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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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
Back
Top