Microsoft Office Tutorials and References
In Depth Information
Adding spin buttons to UserForms
Adding spin buttons to UserForms
With Excel VBA UserForms, you and your colleagues can enter data quickly. Text boxes are
flexible, but you can take more control over the numbers a user enters by linking a spin
button to a text box. Clicking the spin button’s up or down arrow changes the value in the
attached control by an amount that you define.
To create a spin button, click the UserForm and then, in the Toolbox, click the SpinButton
control and draw the spin button on the UserForm. Next, click the spin button and then, in
the Properties panel, change the values of these properties:
Max The largest value allowed in the spin button
Min The smallest value allowed in the spin button
SmallChange The amount that each click changes the spin button’s value
Suppose you create a spin button with a Min value of 1 , Max value of 10 , and SmallChange
value of 1 . Each click of the up button would increase the value by 1 (to a maximum of 10)
and each click of the down button would decrease the value by 1 (to a minimum of 1).
After you create the spin button, create a text box to display the value assigned to the spin
control. Write down the name of the text box, which you can discover by clicking the text
box and observing the value of the Name property in the Properties panel.
Right-click the spin button and, from the shortcut menu that appears, click View Code.
Doing so displays the outline of the event code that will run when the value of the spin
button changes. To link the spin button with the text box, you set the text control’s Value
property so that it is equal to the same property of the spin button.
If the text box were named PackageOunces and the spin button were named OuncesSpin ,
your code would look like the following example.
Private Sub OuncesSpin_Change()
PackageOunces.Value = OuncesSpin.Value
End Sub
Search JabSto ::

Custom Search