VBA & Macro Problems

Create an Excel Input Box to Add Values and Display a Total

Adam DavisAdam Davis Nov 18, 2026 870 views

Question details

The user wants to enter values in Excel, add them like a calculator, and show the total in another cell.

Create an Excel Input Box to Add Values and Display a Total
Product
Microsoft Excel
Device & OS
not provided
Scenario
Enter several numbers and display their sum in a worksheet cell, optionally using a pop-up input box.
Observed behavior
The desired result is a total that updates as values are entered.
Before you start

Choose a worksheet cell for the total and decide whether you need a pop-up or can enter numbers directly into cells. To use the VBA option, open the workbook in a desktop version of Excel that supports macros.

Solution 1Recommended

Add numbers with a VBA input box in Excel

Use this option to enter numbers one at a time in a pop-up and show the running total in cell B1.

The macro starts a new total each time it runs. It updates B1 after each entry and stops when you select Cancel.

1
Open the VBA editor

In Excel, open the target workbook and choose Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon settings.

2
Insert the macro

In the VBA editor, select Insert > Module and paste this code: Sub AddValues() Dim entry As Variant Dim total As Double Dim target As Worksheet Set target = ActiveSheet total = 0 target.Range("B1").Value = total Do entry = Application.InputBox("Enter a number, or select Cancel to finish:", "Add values", Type:=1) If VarType(entry) = vbBoolean Then Exit Do total = total + CDbl(entry) target.Range("B1").Value = total Loop End Sub

3
Save as a macro-enabled workbook

Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) to retain the macro.

4
Run and enter values

Return to the worksheet where you want the total, choose Developer > Macros, select AddValues, and click Run. Enter each number and select OK; select Cancel when finished. The total appears in B1.

Add numbers with a VBA input box in Excel
Change the result cell: Replace both instances of "B1" in the code with your preferred cell address. The macro overwrites that cell when it starts.
WPS Spreadsheets

Add values with a running total in WPS Spreadsheets

Use WPS Spreadsheets to enter numbers in a worksheet range and display their sum in another cell. This formula-based approach does not require a pop-up or macro.

  1. 1. Open a spreadsheet: Open WPS Office, select Spreadsheets, and create a blank workbook or open an existing one.
  2. 2. Set up the total: Select cell B1, type =SUM(A1:A10), and press Enter.
  3. 3. Enter your numbers: Type values into cells A1 through A10 and check the updated total in B1.
  4. 4. Save the workbook: Choose File > Save As and select an Excel-compatible format such as XLSX.
Automatically update a total as you enter valuesOpen and edit Microsoft Excel XLS and XLSX filesUse a familiar spreadsheet interfaceCreate a total without writing VBA
QA img-9

Frequently Asked Questions

How do I stop the Excel input box?

Select Cancel in the input box. The macro stops and leaves the current total in B1.

Can I display the total in a different cell?

Yes. In the VBA editor, replace both instances of "B1" with the cell address you want to use, such as "C1".

Will the macro keep the previous total when I run it again?

No. This macro resets the total to zero and overwrites B1 each time you run it.

Why should I save the workbook as an XLSM file?

The Excel Macro-Enabled Workbook format retains VBA macros. Choose File > Save As and select *.xlsm before closing the workbook.

Can I add values without using VBA?

Yes. Enter =SUM(A1:A10) in B1, then type your numbers in A1 through A10. The total updates automatically.