Show Result in Userform TextBox as a percentage

Hutch1603

New Member
Joined
Apr 23, 2013
Messages
26
Hello,

I have a user form with 3 text boxes and 2 command buttons. My problem is getting text box 3 to perform a calculation based on cost price in text box 1 and the percentage I need to reduce it by to show the discounted buying price. So for example, if a product costs £100, take 20% off, then £80 should show in text box 3. Just cant figure out the code to get it to do this.

My user form loads, my command buttons to clear the text boxes 1&2 works, my command button to close the user form works. I have been trying to perform the calculation as follows:

Private Sub CalcDec()
TextBox3.value = ((TextBox1.value) - (1-(Textbox2.Value)))
End Sub

Additionally, I have the formula stared in Sheet1 of my workbook in cell B5. My formula is =B3-(1-(B4))

I have tried to use If and When Statements, all with no Luck. Can anyone point me in the right direction.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
In the control source for Properties of textbox3 insert Sheet1!B5 if I understand your needs. HTH. Dave
 
Upvote 0
Exactly what do you have in textbox1 100 or £ 100.
In textbox2 20 or 20% or 0.20

If you have in textbox1 100
and in textbox2 20

then try:

Code:
TextBox3.Value = CDbl(TextBox1.Value) * (1 - (CDbl(TextBox2.Value) / 100))
 
Upvote 0
Try this.
Code:
Private Sub CalcDec_Click()
    TextBox3.Value = TextBox1.Value * (1 - TextBox2.Value / 100)
End Sub
 
Upvote 0
Thank you for your responses. Unfortunately, I still can't get TextBox3 to show the result. I'm sure I must have missed something. My current code is as Follows:

Code:
Private Sub OptionButton1_Click()


    'This opens the user form
       
    PerDecCalc.Show
    
End Sub


Private Sub CalcDec_Click()


    TextBox3.Value = TextBox1.Value * (1 - TextBox2.Value / 100)
    
End Sub


Private Sub CommandButton1_Click()
        
    'This clears the text boxes
        
    TextBox1.Value = ""
    TextBox2.Value = ""
        
End Sub


Private Sub CommandButton2_Click()


    'This closes the user form
    
    Unload PerDecCalc
    
End Sub

[Code]
 
Upvote 0
Do you have a command button named CalcDec?
 
Upvote 0
In your original post you had this for doing the calculation.
Code:
Private Sub CalcDec()
    TextBox3.value = ((TextBox1.value) - (1-(Textbox2.Value)))
End Sub

When/how do you want that to be executed?
 
Upvote 0
Perform a small test on a new userform, only add 3 textbox
In the textbox1 write 100
In the textbox2 write 20
Create a commandbutton and add the following code

Code:
Private Sub CommandButton1_Click()
    TextBox3.Value = CDbl(TextBox1.Value) * (1 - (CDbl(TextBox2.Value) / 100))
End Sub


Execute the form, press the button and in the textboxt3 an 80 should appear.
 
Upvote 0
Thank you for your answers. I will try these tomorrow and come back to you as I forgot to bring my memory stick home.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,928
Members
449,195
Latest member
Stevenciu

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