Automatically update textboxes on userform

mmix803

New Member
Joined
Sep 21, 2024
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
I am new to vba. Is it possible to automatically update textboxes on userform. I have a qtytxt textbox multiplying a ratetxt textbox = amounttxt textbox. If you put in the qtytxt textbox (10) time ratetxt textbox ($10.00) = amounttxt textbox ($100.00) then go back to change either the qty or rate so that the amounttxt shows the correct value after you update it.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try:

VBA Code:
Private Sub qtytxt_Change()
  Call updateAmount
End Sub
Private Sub ratetxt_Change()
  Call updateAmount
End Sub

Sub updateAmount()
  Dim q As Double, r As Double
  If qtytxt <> "" And IsNumeric(qtytxt) Then
    q = CDbl(qtytxt)
  End If
  If ratetxt <> "" And IsNumeric(ratetxt) Then
    r = CDbl(ratetxt)
  End If
  amounttxt = q * r
End Sub
 
Upvote 0
Solution
You can update it like this, could you please try and share the result?

VBA Code:
Private Sub qtytxt_Change()
    Call UpdateAmount
End Sub

Private Sub ratetxt_Change()
    Call UpdateAmount
End Sub

Private Sub UpdateAmount()
    Dim qty As Double
    Dim rate As Double
    Dim amount As Double

    If IsNumeric(qtytxt.Text) Then
        qty = CDbl(qtytxt.Text)
    Else
        qty = 0
    End If

    If IsNumeric(ratetxt.Text) Then
        rate = CDbl(ratetxt.Text)
    Else
        rate = 0
    End If

    amount = qty * rate

    amounttxt.Text = Format(amount, "Currency")
End Sub
 
Upvote 0
Try:

VBA Code:
Private Sub qtytxt_Change()
  Call updateAmount
End Sub
Private Sub ratetxt_Change()
  Call updateAmount
End Sub

Sub updateAmount()
  Dim q As Double, r As Double
  If qtytxt <> "" And IsNumeric(qtytxt) Then
    q = CDbl(qtytxt)
  End If
  If ratetxt <> "" And IsNumeric(ratetxt) Then
    r = CDbl(ratetxt)
  End If
  amounttxt = q * r
End Sub
[/CO
[/QUOTE]

You can update it like this, could you please try and share the result?

VBA Code:
Private Sub qtytxt_Change()
    Call UpdateAmount
End Sub

Private Sub ratetxt_Change()
    Call UpdateAmount
End Sub

Private Sub UpdateAmount()
    Dim qty As Double
    Dim rate As Double
    Dim amount As Double

    If IsNumeric(qtytxt.Text) Then
        qty = CDbl(qtytxt.Text)
    Else
        qty = 0
    End If

    If IsNumeric(ratetxt.Text) Then
        rate = CDbl(ratetxt.Text)
    Else
        rate = 0
    End If

    amount = qty * rate

    amounttxt.Text = Format(amount, "Currency")
End Sub
You can update it like this, could you please try and share the result?

VBA Code:
Private Sub qtytxt_Change()
    Call UpdateAmount
End Sub

Private Sub ratetxt_Change()
    Call UpdateAmount
End Sub

Private Sub UpdateAmount()
    Dim qty As Double
    Dim rate As Double
    Dim amount As Double

    If IsNumeric(qtytxt.Text) Then
        qty = CDbl(qtytxt.Text)
    Else
        qty = 0
    End If

    If IsNumeric(ratetxt.Text) Then
        rate = CDbl(ratetxt.Text)
    Else
        rate = 0
    End If

    amount = qty * rate

    amounttxt.Text = Format(amount, "Currency")
End Sub
Works awesome. Thank you. I am a access person and learning vba and userforms are a challenge to me. Access to me is easier. Many thanks. I am not as sharp as I used to be. Getting old sucks...LOL
 
Upvote 0
Works awesome
Apparently they copied my code from post #2, I only see that they added the format, in which case, here is the format:

VBA Code:
amounttxt = format(q * r, "Standard")

Note: rate = 0, It is not necessary, since when declaring the variable, the initial value is 0.
1729119090979.png
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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