Format User Form Field

Adrae

Active Member
Joined
Feb 19, 2002
Messages
306
How can I format one of the user for input fields as a precentage?

Thanks :)
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I am using VBA, but am not sure where I can find this function or how to use it. Would you be able to provide me with the sample code?
 
Upvote 0
Does anyone have sample code for how to format a user form field as a percentage?

I tried:
Private Sub TextBox3_Change()
TextBox3 = Format(TextBox3, "0%")
End Sub

But the act of typing 1 causes the value to default to 100% as opposed to 1%.

What am I doing wrong?

Thanks :)
 
Upvote 0
I figured out the FormatPercent Function but need to figure out how to make it so that typing in 1 yields 1% not 100%. Does anybody have any ideas how to do this?

Thanks

My code is:
Private Sub TextBox3_Change()
TextBox3 = FormatPercent(TextBox3)
End Sub
 
Upvote 0
I get a type mismatch error for

TextBox3 = FormatPercent(TextBox3 / 100)

Any idea why?
 
Upvote 0
You can't divide until you change the string in your text box to a number. Try formatpercent(csng(textbox3)/100). Csng will change the value to a single. Now you have to be careful that the user puts something that can be changed to a number in there. If they don't there will be an error. You can use the isnumeric funtion for that in an if statement. Error trapping is also the hardest part of using text boxes.

Also, usually you'd use text property of the textbox function to get the value (textbox3.text). I'm not sure if you're using this or not.

Dave
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

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