VBA coding

HWake

New Member
Joined
Oct 15, 2018
Messages
2
Hi all,

Apologies, I'm new to this and new to coding so I will sound as though I'm clueless!

Im creating a userform through VBA and I need to get some of the boxes I have created (label boxes) to add up the value that is in the text boxes (in some cases I need them to multiply). Does anyone know a code for this and even if I'm going the right way of doing it, as in using label boxes?

Thanks,

Hana x
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
So you are wanting a label to display the added up values of several Textboxes
I believe is what you want.

Try something like this:

Code:
Private Sub CommandButton2_Click()
'Modified  10/19/2018  7:35:59 AM  EDT
Label1.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value)
End Sub
 
Last edited:
Upvote 0
Hi My Answer Is This,

Thank you so much for your help, but is there a way of the label boxes auto adding / multiplying the values in the textboxes without the use of a commandbutton at all?

Thanks,

Hana x
 
Upvote 0
Well we can have them add up as you exit the textbox.

And we call them Labels.
Not Label Boxes.


You will need something like this:

I have this working for two Textboxes

If you have more then you will need to add more

The initialize code sets Label1 initial value to 1


Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label1.Caption = Label1.Caption + CDbl(TextBox1.Value)
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label1.Caption = Label1.Caption + CDbl(TextBox2.Value)
End Sub
Private Sub UserForm_Initialize()
Label1.Caption = "0"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,020
Members
452,542
Latest member
Bricklin

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