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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

Forum statistics

Threads
1,136,991
Messages
5,679,004
Members
419,797
Latest member
ikethegenius

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