In this article, we will demonstrate how to insert and rotate a spin button in Excel to change a value.
What Is a Spin Button?
A Spin Button is a form element that allows you to easily increase or decrease a value, like incrementing a number, date, or time. By clicking the up arrow, the value can be increased; and by clicking the down arrow, it can be decreased. A Spin Button can be used as form of Data Validation to avoid typing a value in a cell.
Spin Buttons in Excel
We have two forms of Spin Buttons in Excel, which can be found in the Developer tab under the Insert group. The Spin Button presented in the Form Controls group can be assigned directly to a cell but can’t be rotated. The Spin Button presented in the ActiveX Control group can be rotated, however some VBA code is required to assign it to a cell.
In this article, we will use the Spin Button presented in the ActiveX Control group.
Read More: How to Use Spin Button in Excel
Step-by-Step Procedures to Rotate a Spin Button in Excel
Step 1 – Making a Dataset
To demonstrate the use of a Spin Button, we’ll use the following dataset, which has values for Monthly Salary and Additional Monthly Earnings. First, we’ll find the Yearly Earnings.
- Enter the following formula in cell C6:
=(C4*12)+(C5*12)
- Press ENTER to return the result.
Next, we’ll insert a Spin Button and assign it to cell C5, so that every time we click on the spin button, the value of C5 (Additional Monthly Earning) will change, and accordingly, so will the value of the Yearly Earnings.
Step 2 – Inserting a Spin Button from Form Controls
Let’s insert a Spin Button.
- Go to the Developer tab >> click on Insert.
- From the ActiveX Control group, click on the Spin Button marked in the image below with a red box.
- Place the Spin Button next to the dataset.
Step 3 – Rotating the Spin Button
Now we’ll rotate our Spin Button.
- Click on the Spin Button.
A dragging arrow appears at the bottom right corner of the Spin Button.
- Drag the Spin Button with this arrow, and rotate it to either the horizontal or vertical position.
We have rotated the Spin Button.
Here is a visual walkthrough of the process:
Step 4 – Inserting VBA Code
Now we’ll assign some code to the Spin Button so that every time we click on a button, the value of the dataset changes. In this case, we want to change the value of cell C5 with the Spin Button.
- Right-click on the Spin Button.
- From the Context Menu, select View Code.
A VBA Editor window will appear.
- Enter the following code in the VBA Editor window:
Private Sub SpinButton1_SpinUp()
With Range("C5")
.Value = WorksheetFunction.Min(1000, .Value + 50)
End With
End Sub
Private Sub SpinButton1_SpinDown()
With Range("C5")
.Value = WorksheetFunction.Max(300, .Value - 50)
End With
End Sub
- Save the code.
- Run the code.
- Return to the worksheet and click on the Spin Button.
The value in cell C5 changes every time we click on the Spin Button, as does the Yearly Earnings.
Read More: How to Control Multiple Cells with Spin Button in Excel
Download Workbook
Related Articles
- Using Spin Button to Increment Decimal in Excel
- [Solved!] Excel Spin Button Not Working
- How to Add Up and Down Buttons in Excel