dynamically add TextBox value in worksheet

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows
I have a user form with a textbox. On the same form, I'd like to show the product of the value that is entered in this textbox and another cell value in a Label.
The problem is that the value is only pasted at the cell after pressing a control button to confirm, so the label does not show anything in real time. Is this possible anyway?
I had the following code:

VBA Code:
Private Sub btnNEXT1_Click()
    Sheets("Data").Select
    Range("A" & CStr(Rows.Count)).End(xlUp).Select
    ActiveCell.Offset(2, 0).Value = TextBox1.Value
    Unload Me
    frmSSD.Show vbModeless
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Private Sub TextBox1_Change()
   If Me.TextBox1 <> "" Then
      Me.Label1.Caption = Me.TextBox1.Value * Range("A1").Value
   Else
      Me.Label1.Caption = ""
   End If
End Sub
 
Solution

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hello Fluff,
Many thanks! I even can show the product of two different textboxes real time.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

BTW, is it possible to add a number format to the result number shown in the Label?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
Yup, like
VBA Code:
      Me.Label1.Caption = Format(Me.TextBox1.Value * Range("A1").Value, "#,##0.00")
 

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Working with this solution, is it also possible to add up two values, like:
VBA Code:
Me.Label23.Caption = Format((Me.TextBox2.Value / 12) + (Me.TextBox3.Value / 12), "#,##0")

I get error 13 Type mismatch
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
That should be fine as long as neither textbox is blank nor contain text.
 

Forum statistics

Threads
1,141,619
Messages
5,707,449
Members
421,509
Latest member
kt_mr_excel

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