Passing Text Box value to another Text Box

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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]
 
Upvote 0
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]_-;_-@_-"
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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