Spin Button Control

The spin button control uses the SpinDown and SpinUp events to decrease and increase the value in cell B4:

'Spin down event procedure for spin button Private Sub SpinButton1_SpinDown()

With Range("B4")

'Decrease value in B4 by .05%. Stop at 0% .Value = WorksheetFunction.Max(0, .Value - 0.0005)

End With

End Sub

'Spin up event procedure for spin button

Private Sub SpinButton1_SpinUp()

With Range("B4")

.Value = WorksheetFunction.Min(0.01, .Value + 0.0005)

End With

End Sub

The Value property of the spin button is ignored. It is not suitable to be used directly as a percentage figure because it can only be a long integer value. The events are used as triggers to run the code that operates directly on the value in B4. The growth figure is kept in the range of zero to 1 percent.

Clicking the down side of the spin button runs the SpinDown event procedure, which decreases the value in cell B4 by 0.05%. The worksheet Max function is used to ensure that the calculated figure does not become less than zero. The SpinUp event procedure increases the value in cell B4 by 0.05%. It uses the Min function to ensure that the calculated value does not exceed 1%.

0 0

Post a comment