Passing Text Box value to another Text Box

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
158
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have an inquiry in a userform, if you may help me


I have the following textboxes that calculate some values

txtAmount has a calculation which I have the code for it and all the below text boxes as well, unless the "txtPaid"

I need "txtPaid" to be the same as the "txtTotal" but to be able to change it's value
ex: if txtTotal.value = 100, then, txtPaid.value = 100, and then I can change the value of the txtPaid if I need


Code:
Private Sub txtDiscount_Change()
Call txtTotal_Change
End Sub

Private Sub txtTotal_Change()
Me.txtTotal = Me.txtAmount - Me.txtDiscount
Call txtPaid_Change
Call txtRest_Change
End Sub


Private Sub txtPaid_Change()
Me.txtPaid.Text = Me.txtTotal 'I've tried this but I can't change the value
Call txtRest_Change
End Sub


Private Sub txtRest_Change()
Me.txtRest = Me.txtTotal - Me.txtPaid
End Sub
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,384
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtDiscount_Change()
    Me.txtTotal = Me.txtAmount - Me.txtDiscount
    Me.txtPaid.Text = Me.txtTotal
    Me.txtRest = Me.txtTotal - Me.txtPaid
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtTotal_Change()
    Me.txtPaid.Text = Me.txtTotal
    Me.txtRest = Me.txtTotal - Me.txtPaid
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtPaid_Change()
    Me.txtRest = Me.txtTotal - Me.txtPaid
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtRest_Change()


[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
158
Office Version
  1. 2016
Platform
  1. Windows
Thank you AlphaFrog this is exactly what I need, and one more thing I forgot to mention, if possible I need the format of these five text boxes to be (L.L.)
Here is the format for the cells but I don't have the code for the same
"_-* #,##0 [$L.L.þ-ar-LB]_-;-* #,##0 [$L.L.þ-ar-LB]_-;_-* ""-"" [$L.L.þ-ar-LB]_-;_-@_-"
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,384
I don't know what that format is. It doesn't work for my version of Excel.

Try something like this. I can't test it. You may have to adjust it.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtDiscount_Change()
    Me.txtTotal = Format(CCur(Me.txtAmount) - CCur(Me.txtDiscount), "_-* #,##0 [$L.L.þ-ar-LB]_-;-* #,##0 [$L.L.þ-ar-LB]_-;_-* ""-"" [$L.L.þ-ar-LB]_-;_-@_-")
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtTotal_Change()
    Me.txtPaid.Text = Format(CCur(Me.txtTotal), "_-* #,##0 [$L.L.þ-ar-LB]_-;-* #,##0 [$L.L.þ-ar-LB]_-;_-* ""-"" [$L.L.þ-ar-LB]_-;_-@_-")
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtPaid_Change()
    Me.txtRest = Format(CCur(Me.txtTotal) - CCur(Me.txtPaid), "_-* #,##0 [$L.L.þ-ar-LB]_-;-* #,##0 [$L.L.þ-ar-LB]_-;_-* ""-"" [$L.L.þ-ar-LB]_-;_-@_-")
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] txtRest_Change()


[color=darkblue]End[/color] [color=darkblue]Sub[/color]

Notice that if you change txtDiscount, the code in txtDiscount_Change procedure changes txtTotal and it will automatically trigger the txtTotal_Change procedure which in-turn changes and triggers txtTPaid...etc.
 

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
158
Office Version
  1. 2016
Platform
  1. Windows
Thank you so much AlphFrog for your time, it didn't work as I need, but no problem
Can you please give me one more favor?
I have the following codes for the 5 text boxes, and just need values with thousands separators if it's possible please


Code:
Private Sub txtAmount_Change()Dim MySum   As Double
    MySum = 0
    With ListBox1
        For r = 0 To .ListCount - 1
            MySum = MySum + .List(r, 5)
        Next r
    End With
txtAmount.Value = MySum
Call txtTotal_Change
Call txtDiscount_Change
End Sub


Private Sub txtDiscount_Change()
    Me.txtTotal = Me.txtAmount - Me.txtDiscount
    Me.txtPaid.Text = Me.txtTotal
    Me.txtRest = Me.txtTotal - Me.txtPaid
End Sub


Private Sub txtTotal_Change()
    Me.txtPaid.Text = Me.txtTotal
    Me.txtRest = Me.txtTotal - Me.txtPaid
    Call txtDiscount_Change
    Call txtPaid_Change
End Sub


Private Sub txtPaid_Change()
    Me.txtRest = Me.txtTotal - Me.txtPaid
End Sub
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,384
Use something like this...

Code:
txtAmount.Value = Format(MySum, "#,##0")
 

Watch MrExcel Video

Forum statistics

Threads
1,122,961
Messages
5,599,061
Members
414,281
Latest member
Engjamal2021

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
Top