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

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
66
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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