Format Text box as a percent

greenae

Board Regular
Joined
May 25, 2005
Messages
96
Hi-
I have a userform that asks the user to enter a percentage. I have code that takes the value (i.e. 10) and formats it to 10% in the textbox:

MakePercent = Format(RawValue / 100, "#%")

However, when I need to multiply that percent value later in the code, it won't let me as I it reads the formatted value as a string.

How do I format it as a percentage, yet, have it remain a numeric value?

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,
to get the data without % you can use
Code:
Left(TextBox1, Len(TextBox1) - 1)
check out the functions Left & Len in VBA: they are quite the same as the worksheetfunctions

kind regards,
Erik
 
Upvote 0
greenae

If you want to get the value to use in a calculation use Val.
Code:
Dim strValue As String

     strValue = Format(10 / 100, "#%")

     MsgBox strValue & " of 500 is " & Val(strValue) / 100 * 500
 
Upvote 0
You just about had it!


Sub myPercent()
'Standard module code, like: Module1.
Dim myPCent$
Dim myVal#

myVal = 0.89

myPCent = Application.WorksheetFunction.Text(myVal, "#.00%")
MsgBox myPCent

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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