Create Excel Macro Buttons to Increase or Decrease Inventory Values by Row
Question details
Create controls that add or subtract one from the currently selected numeric inventory cell in an Excel worksheet.

- Product
- Microsoft Excel VBA macros and Form Control spin buttons
- Device & OS
- not provided
- Scenario
- The user needs tablet-friendly inventory controls that can adjust values by row without creating separate macros for every row.
- Observed behavior
- The desired controls should update only valid numeric cells in the target inventory range and warn the user when another cell is selected.
Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm) before adding VBA code. Identify the inventory value range first; the example below uses column D starting at D2.
Use one pair of VBA macros to adjust the active inventory cell
Use this method when one Plus One button and one Minus One button should update whichever valid cell is currently selected in column D.
The shared AdjustValue procedure checks whether the active cell is inside the used portion of column D and whether it contains a numeric value. This avoids maintaining separate macros for each inventory row.
In Excel desktop, press Alt+F11, then select Insert > Module to create a standard VBA module.
Paste the following code into the module: Private Sub AdjustValue(ByVal amount As Double) Dim target As Range Set target = Intersect(ActiveCell, ActiveSheet.Range("D2:D" & ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row)) If target Is Nothing Then MsgBox "Select a cell in column D.", vbExclamation ElseIf IsNumeric(target.Value) Then target.Value = target.Value + amount Else MsgBox "The selected cell is not numeric.", vbExclamation End If End Sub Sub MinusOne() AdjustValue -1 End Sub Sub PlusOne() AdjustValue 1 End Sub
Return to the worksheet, choose Developer > Insert, and add two Button (Form Control) objects. Right-click each button, select Assign Macro, and assign PlusOne to one button and MinusOne to the other.
Move the buttons to the header area, then choose View > Freeze Panes > Freeze Top Row so the controls remain visible while you scroll through inventory rows.

Link Form Control spin buttons directly to inventory cells
Use spin buttons when each row needs its own on-sheet increment and decrement control with fixed whole-number limits.
Add inventory increment controls in WPS Spreadsheets
WPS Spreadsheets provides familiar worksheet tools for building inventory tables, entering numeric values, and organizing row-based updates. For macro-enabled workflows, open the workbook in WPS Office desktop, use the Developer tools available in your installation, and save the file in a macro-enabled Excel format when VBA compatibility is required.
- 1. Open the inventory workbook: Launch WPS Spreadsheets and choose Menu > Open to select your inventory workbook.
- 2. Select the quantity range: Click the first inventory quantity cell in column D, then verify that the column contains numeric values for incrementing and decrementing.
- 3. Add data validation limits: Select the inventory range, then choose Data > Data Validation and set an allowed whole-number range, such as 0 through 5000.
- 4. Save in a compatible format: Choose Menu > Save As and select Excel Macro-Enabled Workbook (*.xlsm) when the workbook includes VBA macros, or Excel Workbook (*.xlsx) for standard spreadsheets.

Frequently Asked Questions
Can one Excel macro button work for every inventory row?
Yes. A macro can use ActiveCell and Intersect to determine whether the selected cell is in the permitted inventory range, such as D2 through the last used cell in column D, before changing its value.
Why does the macro say to select a cell in column D?
The active cell is outside the range defined in the VBA code. Select a numeric cell in column D, or edit the range reference in AdjustValue if your inventory values are stored elsewhere.
How do I prevent inventory quantities from dropping below zero?
Add a lower-limit check before updating the cell, or use Data > Data Validation to allow only whole numbers greater than or equal to 0. Form Control spin buttons can also use a Minimum value of 0.
Can I use Excel macro buttons on a tablet?
Excel mobile apps generally have limited VBA and Form Control support. Create, assign, and test VBA buttons in Excel desktop first; on a tablet, use a simplified input workflow or controls supported by the app version.
What is the difference between macro buttons and spin buttons?
Macro buttons run VBA code and can validate the currently selected cell, making one pair of buttons suitable for many rows. Spin buttons are linked to individual cells and provide direct whole-number changes with configured limits.




