How to Sum Textbox Values in Excel VBA
- 1). Click the "Developer" tab, click "Visual Basic," and click the "Insert" menu. Click "UserForm" to insert a new form and click "ComboBox" to select it from the Toolbox pane. Click form to insert a combo box. Add a command button using the same technique.
- 2). Double-click the command button to create a button click event. Create a global variable to this code module by adding the following line of code to the very top of the module:
Public txtBoxVal As Integer - 3). Add the following code to get the value in the text box and add it to the previous value using the global variable:
txtBoxVal = txtBoxVal + Me.TextBox1.Text - 4). Display the result using a message box.
MsgBox "The total sum of values entered is: " & txtBoxVal - 5). Double-click "UserForm1" from the project explorer window and click "F5" to run the program. Enter a number in the text box and click the button to display the result. Type a different number in the text box and click the button to display the sum of the values entered in the text box control.