Can I do addition, division and multiplication in the same textbox on the userform

Abdo

Board Regular
Joined
May 16, 2022
Messages
183
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
is there any way to do addition, division and multiplication in the same textbox on the userform
this the part of my code and I will implement for multiple textboxes

VBA Code:
Private Sub TextBox12_change()
If TextBox12 <> "" And TextBox23 <> "" Then
  TextBox34.Value = CDbl(TextBox45.Value) / CDbl(TextBox44.Value)
    TextBox34.Value = CDbl(TextBox12) * CDbl(TextBox23) *CDbl(TextBox34.Value)
  End If
End Sub
I have textbox 44 it will sum values multiple textboxes and textbox 45 I have to fill value manually , then the result should be in textbox34 for instance
textbox 44= 87700, textbox45=2000 so the value = 2000/87700=0.022805
textbox 12=10 textbox23=100 result 10*100=1000 then the result in textbox34= 1000*0.022805=22.805
I no know if it's possible or not . any idea to do that ?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I don't see any addition being attempted anywhere in your code.

It seems to me that you should be able to combine these two lines:
VBA Code:
  TextBox34.Value = CDbl(TextBox45.Value) / CDbl(TextBox44.Value)
    TextBox34.Value = CDbl(TextBox12) * CDbl(TextBox23) *CDbl(TextBox34.Value)
to this:
VBA Code:
  TextBox34.Value = CDbl(TextBox12) * CDbl(TextBox23) * (CDbl(TextBox45.Value) / CDbl(TextBox44.Value))

Note there is no Excel VBA limitation. You just need to follow the typical rules of mathematical order of operations .
 
Upvote 0
thanks joe but gives error mismatch in the whole line .
 
Upvote 0
thanks joe but gives error mismatch in the whole line .
That seems to suggest that one of the entries in one of your text boxes is not a number.

If you cannot figure it out, tell us the exact value in each of these text boxes.
 
Upvote 0
actually whole the textboxes are relating with calculation numbers , but I'm fraid becuase using numberformat . every textbox contains this "#,##0.00" but we using function CDbl , how happens that? :unsure:
 
Upvote 0
actually whole the textboxes are relating with calculation numbers , but I'm fraid becuase using numberformat . every textbox contains this "#,##0.00" but we using function CDbl , how happens that? :unsure:
I have no idea what you are asking.
Please tell me/show me the exact value being returned in each of those text boxes.
 
Upvote 0
sorry joe the things have became more complicated . I know why the error occures because the textbox45 is empty . I no know how fix this problem
look the textbox45 it will sum the values for multiple textboxes(textbox34,35.... up to 44) then the total will show in textbox45 ,but it seems calcaultion based on your suggestion happen before show TOTAL value in textbox45 , that's why show the error, any idea please?
 
Upvote 0
It sounds to me like maybe you need to take a step back and plan all this out a little better. and disable certain options until certain things happen (i.e. do not enable them to run this step until the previous step adding up your values is complete).

I am also not sure why you are trying to do all of this in text boxes instead of doing it in Excel cell. It seems that you might be making things a lot harder than they have to be.

Since we really have no idea what your form and Excel file look like, and how everything is supposed to flow, it is hard to give you good advice.
I think we need a lot more background and detail of your project.
 
Upvote 0
ok Joe I will some pictures soon maybe could be more clearly .
 
Upvote 0
based on my codes when fill the QTY and prices will TOTAL =QTY * PRICE and then will sum and show the final TOTAL in textbox green highlighted and I will fill in textbox EXPENSES the value so far is ok ,but the next step is complicated
value should be EXPENSES / TOTAL =200/4000= 0.05 , then 0.05 *1000 =50 then should add to 1000 to become 1,050.00 and the same thing 0.05 *3000 =150 then should add to 3000 to become 3,150.00
PIC1.PNG


PIC2.PNG

I hope this help
 
Upvote 0

Forum statistics

Threads
1,215,421
Messages
6,124,806
Members
449,191
Latest member
rscraig11

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