VBA Userform, multiplying number with percentage

gulli09

New Member
Joined
Dec 28, 2011
Messages
37
I'm designing a userform. I'm multyplying two textboxes together, one of the textboxes is a number and the other one is a percentage.

First of all I had problems changing the format to a percentage. If there is an easier way to change the format that works that would be great as well. The code currently works that way that as soon as both the percentage and the number is in place they multiply together in another textbox. When I change the format to a percentage the calculations aren't able to recognize the percentage for a percentage and return nothing(eg. when the % is added, it's calculated as number*nothing, and thus returning nothing because it doesn't read the percentage as a number as soon as the % is added)

I basically need to trick the calculator into beliving there is no % sign, whilst at the same time showing the % sign to the user.

In a nutshell it's one textbox were the users enters f.x. 15, and the outcome is 15% he then enters a number, f.x. 100 and then in a 3rd textbox it calculates 15%*100 returning 15. What would be the best way to achieve this? I can provide the code if nescessary.
 
As someone might have foreseen I now have a problem. The code above shows the code that I'm using that works flawlessly. However I was wondering if there was any way for the text-boxes to automatically add thousand separators. F.x. if I type 100.000 I get "100.000" but not "100000". The percentage is fine, but the textbox where I write a number I have to write the thousand separator myself, I can write "500.000" but I have to add the "." manually, is there a way for this to happen automatically? Likewise, when the number is multiplied with the percentage it returns "500000" and not "500.000"

Modifying the code above, how can I achieve this?
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Have you considered not adding commas or percentage signs to the textboxes?

That would avoid having to do any of this.
 
Upvote 0
The commas are required because the percentages do in certain settings have extra decimal places. The % sign is because the design of the user-form is very important, even more important then the programming(although the programming has to work of course)

At the moment it does work, surely a code to design the thousand separators can't be too complex?
 
Upvote 0
Would a Label with the one character .Caption %, placed next to the text box meet your visual needs?
 
Upvote 0
Sorry, I should have said not using thousand separators.

As for the percentage sign, could you not just use a small label next to the combobox?
 
Upvote 0
No, because the % is important for the data later on in the table, aside from obviously the visual flaw. From what you are saying I'm guessing coding the thousand separators will be a problem?
 
Upvote 0
What exactly is the problem?

You gave an example 'if I type 100.000 I get "100.000" but not "100000"'.

That seems to be saying you want to get 100000 which doesn't have any separators.
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,411
Members
449,449
Latest member
Quiet_Nectarine_

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