Set Min and Max for Spin Button

phillipclark

Board Regular
Joined
Sep 10, 2013
Messages
65
Greetings All,
My Question today is how do I set a min and max for a Spin Button within my VBA Code below.
The code I am using currently to increment .1 changes. This is working fine but now it will
be necessary to limit the amount a person can change with the SpinButton.

Thank you in advance for your help

Code:
Private Sub SpinButton2_SpinDown()
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value - 0.1
End Sub
Private Sub SpinButton2_Spinup()
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value + 0.1
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
perhaps wrap it in an If Statement

Code:
Private Sub SpinButton2_SpinDown()
Dim min As Integer
Dim current As Double
min = 0
current = Worksheets("Sheet2").Range("U51").Value
If current > min Then
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value - 0.1
Else
Msgbox "You have reached the minimum amount allowed!"
End If
End Sub

Private Sub SpinButton2_Spinup()
Dim max As Integer
Dim current As Double
max = 10
current = Worksheets("Sheet2").Range("U51").Value
If current < min Then
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value + 0.1
Else
Msgbox "You have reached the maximum amount allowed!"
End If
End Sub
 
Last edited:
Upvote 0
Thank You Nine Zero! This works great. I found only one small mistake and corrected it in the Spin Up Sub Thank You for this help I couldn't have solved without you.

Code:
Private Sub SpinButton2_SpinDown()
Dim min As Integer
Dim current As Double
min = 57
current = Worksheets("Sheet2").Range("U51").Value
If current > min Then
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value - 0.1
Else
MsgBox "You have reached the minimum amount allowed!"
End If
End Sub
Private Sub SpinButton2_Spinup()
Dim max As Integer
Dim current As Double
max = 60
current = Worksheets("Sheet2").Range("U51").Value
If current < [COLOR=#00ffff]max[/COLOR] Then
Worksheets("Sheet2").Range("U51").Value = Worksheets("Sheet2").Range("U51").Value + 0.1
Else
MsgBox "You have reached the maximum amount allowed!"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top