Percents in VBA

billyshears

Board Regular
Joined
Aug 29, 2013
Messages
58
Cell A1=a variable value

I have a userform that I can type numbers into. In the userform I type 10

I then want that number I entered in the userform to multiply Cell A1 by the userform number %

So if I type 10 in the userform, I want cell A1 to increase by 10%

If I type 5 into the userform, Cell A1 increases by 5%

I cant seem to get this working correctly. Do I format the text box in the userform as a %? or is this done in the VBA coding?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

rondeondo

Board Regular
Joined
Aug 15, 2012
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Hi Billy
your form is able to take anything as input, to make it robust you'll want to validate anything entered to be a number so the code doesn't break when someone types in their name. On your form label the field with a % after it so the user doesn't think they need to include the % symbol.
then in the VBA you want something like cells("A1").value = cells("A1").value * (1+<value from form)/100)
 

Forum statistics

Threads
1,140,923
Messages
5,703,178
Members
421,280
Latest member
Jaycee01

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