validate textboxes to be percentage

buzz71023

Active Member
Joined
May 29, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
I have a Calculator that multiples a number by a bunch of percentages that are entered into different text boxes below those results are displayed into text boxes across from the percentage. Something is either wrong with my formula or I need to change the textboxes to allow for percentages (with four decimal places) to be accepted.

When calulating I used 100 * 25% and the result was 2500 (should have been 25), then I used 100 * .25 and it worked correctly.

Here is my code:
Private Sub cmdCalculate_Click()
txtRM1e = Val(txtBlnd) * Val(txtRM1)
txtRM2e = Val(txtBlnd) * Val(txtRM2)
txtRM3e = Val(txtBlnd) * Val(txtRM3)
txtRM4e = Val(txtBlnd) * Val(txtRM4)
txtRM5e = Val(txtBlnd) * Val(txtRM5)
txtRM6e = Val(txtBlnd) * Val(txtRM6)
txtTtlRM = Val(txtRM1e) + Val(txtRM2e) + Val(txtRM3e) + Val(txtRM4e) + Val(txtRM5e) + Val(txtRM6e)
txtTtlPer = Val(txtRM1) + Val(txtRM2) + Val(txtRM3) + Val(txtRM4) + Val(txtRM5) + Val(txtRM6)

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
The percent symbol in VBA indicates an integer data type, e.g., 1% is an integer, 1& is a long, 1! is a Single, and 1# is a Double.

If you want the percent sign to appear in the textbox, you can divide Val by 100. It the textbox can include decimals (10.3%), replace the % symbol with nothing and divide by 100.
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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