Finance

Charts

Statistics

Macros

Search

ScrollBar and SpinButton with Excel VBA

The ScrollBar control is used to set a numeric value, but it can only assign non-negative integer values.
The main event of the ScrollBar control is the Change event, and its main properties are Value, Min, and Max, which set the current, minimum, and maximum values, respectively.

The SpinButton control is functionally similar to the ScrollBar, but it does not have a slider.

Synchronized operation of a text box and a spin button
A spin button allows you to set an integer value, which can then be displayed in a text box.
How can we make the operation of the text box and spin button synchronized, so that the current value of the spin button appears in the text box, and a number entered in the text box becomes the value of the spin button?

In this case, both the spin button and the text box must have their Change events handled in coordination.

So, create a form containing a text box and a spin button.
In the form module, type the necessary code.

When reading data from the text box, before assigning it to the Value property of the spin button, you must verify whether the data is numeric. This can be done using the IsNumeric() function.

In addition, you must check whether the number lies within the valid range of values for the spin button, i.e., within the interval defined by the Min and Max properties of the spin button.

In this example, the values of these properties are set to 1 and 5 during form initialization.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx