How show and use percentage (%) into textboxs on userform

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
55
Office Version
  1. 2019
Platform
  1. Windows
Hello
I have some lines to try show number with percentage in textbox3 after divide textbox1/ textbox2 and multiply percentage in texbox1 to show result in textbox4
VBA Code:
Private Sub TextBox2_AfterUpdate()
 Format(TextBox3.Value, "0.00%") = CDbl(TextBox1.Value) / CDbl(TextBox2.Value)
 TextBox4.Value = CDbl(TextBox1.Value) * CDbl(TextBox3.Value)
example :
textbox1=1,000.00
textbox2=8,000.00
result in textbox3 should be =12.50%
result in textbox4 should be =1,000.00 * 12.50%=125.00(warning :when multiply percentage should be 1,000.00*12.5/100 to show right result)
currently show error object required in first line .
any body help me ,please?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Before using CDBL, check that the textboxes are different from empty and also have a numerical value, otherwise it will send a type error,

Try:

VBA Code:
Private Sub TextBox2_AfterUpdate()
  If TextBox1.Value <> "" And TextBox2.Value <> "" Then
    TextBox3.Value = Format(CDbl(TextBox1.Value) / CDbl(TextBox2.Value), "0.00%")
  End If
  If TextBox1.Value <> "" And TextBox3.Value <> "" Then
    TextBox4.Value = Format(CDbl(TextBox1.Value) * CDbl(Replace(TextBox3.Value, "%", "")), "Standard")
  End If
End Sub
 
Upvote 0
Thanks but I'm afraid will show wrong result in textbox4 .
I explained in this
warning :when multiply percentage should be 1,000.00*12.5/100 to show right result)
should show 125.00 , not 12,500.00 .
 
Upvote 0
Just divide by 100:

VBA Code:
Private Sub TextBox2_AfterUpdate()
  If TextBox1.Value <> "" And TextBox2.Value <> "" Then
    TextBox3.Value = Format(CDbl(TextBox1.Value) / CDbl(TextBox2.Value), "0.00%")
  End If
  If TextBox1.Value <> "" And TextBox3.Value <> "" Then
    TextBox4.Value = Format(CDbl(TextBox1.Value) * CDbl(Replace(TextBox3.Value, "%", "") / 100), "Standard")
  End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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