Shows multiple Textboxes value on one Textbox, Like an autosum

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,831
Office Version
  1. 2007
Platform
  1. Windows
On my userform TextBox17 should show the value of multiple textboxes like an Autosum.

How is the following correctly written so its not a mile long please.

VBA Code:
Private Sub TextBox17_Change()
TextBox17 = Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text)
End Sub

Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Weird, maybe you can try as you did with "Val(TextBox1.Text)" but it's more error prone. Like so :
Otherwise with no more information i don't know.
VBA Code:
Private Sub TextBox17_Change()
  Dim i As Long, SumV As Double
  For i = 1 to 4
    SumV = SumV + Val(Controls("Textbox" & i).Text)
  Next i
End Sub
For information the "Controls" is only valid inside the UF's code. If you are outside, you need to reference the UF.

Controls object (Access) | Microsoft Learn
 
Upvote 0
No sorry i'm stupid, you just need to write the total in the textbox. Like so :
VBA Code:
Private Sub TextBox17_Change()
  Dim i As Long, SumV As Double
  For i = 1 to 4
    SumV = SumV + CDbl(Controls("Textbox" & i).Value)
  Next i
  ' writing the total
  TextBox17.Value = SumV
End Sub
 
Upvote 0
How is the following correctly written so its not a mile long please.
I don't see long
you can use"_ "after comma "," . four textboxes are not much to use loop !
here is another option
VBA Code:
Me.TextBox17.Value = WorksheetFunction.Sum(Array(CDbl(Me.TextBox1.Value), CDbl(Me.TextBox2.Value), _
                                                                 CDbl(Me.TextBox3.Value), CDbl(Me.TextBox4.Value)))
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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