In the previous Article How to write Excel Macro – Your First Excel Macro of Excel Macro Tutorial, you have seen how to write Excel Macro. Also in Previous Tutorials, you have seen all the basic concept of Excel Macro.
In this Article I am going to show you how to Add and Use Spin Button.
Spin Button: Spin button is an ActiveX Control which have Two Buttons Up and Down. Both the buttons always remain together but function separately. Generally you might have seen this button in many dialog box where user wants to increase or decrease values in a Text box or anywhere by clicking on Up or Down button correspondingly.
How to Add VBA Spin Button in your Excel Sheet
Step 1.Go to Developer’s Tab (How to Add Developer’s Add in to the Ribbon)
Step 2.Go to to Controls Section -> Click on Arrow on INSERT button
Step 3.Click on ActiveX Spin Button
Step 4.Now Drag the Place where you want to Place that button and re-size as per your requirement.
Now you got Added Spin Button to your Excel Sheet. Now we will learn how to make this button working by writing a simple line of code.
How to Use VBA Spin Button in your Excel Sheet
Step 1.Double Click on the Control.
Step 2.You are taken to the Visual Basic Editor of the Excel
Step 3.Here Select the Name of your Control.
Step 4.Now you Select SpinUp and SpinDownEvents from the Even Drop down as shown below in image:
Step 5.Now Copy paste the below Code for your SpinUp Event and SpinDown Event
SpinUp Event
Private Sub SpinButton1_Spinup()
With Range("A1")
.Value = WorksheetFunction.Min(150, .Value + 10)
End With
End Sub
SpinDown Event
Private Sub SpinButton1_Spindown()
With Range("A1")
.Value = WorksheetFunction.Max(50, .Value - 10)
End With
End Sub
in Above Example, Spin button will increase or decrease the Value of Cell A1 by 10 on clicking on Up and Down button respectively. Also down button will not decrease the Value less than 50 and also Up button will not allow to increase for more than 150.
This way you can customize it as per your requirement.
If you face any issue or doubt about this feel free to contact me on info@learnexcelmacro.com
To Check out more Excel Macro Tutorials, visit Excel Macro Tutorial |
Private Sub SpinButton1_Spinup()
With Range(“A1”)
.Value = WorksheetFunction.Min(150, .Value + 10)
End With
End Sub
how could you change this so that the spinner goes up to a set value by another cell?
say you had 100 in d3, but the 100 can change.
hi,thanks for infos.
I’ve used the spinButton with listbox.Namely, to view the data in the listbox(down/up).
You can view : https://netmerkez.wordpress.com/excel/excel-advanced-userform-example/
Hi
my name is sambunteang, I would like to ask you how to use spin-button by assign marco code in it