Passing Text Box value to another Text Box

NDMDRB

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

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,194
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
128
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,194
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
128
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,194
Use something like this...

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

Forum statistics

Threads
1,085,584
Messages
5,384,583
Members
401,911
Latest member
bluesquared

Some videos you may like

This Week's Hot Topics

Top