Excel macro Userform spin button to loop months

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
I'm trying to write a code for a spin button on my user form which I can to loop the months from January to December. When it reaches December and I click the Down/Next/Right button, it should go to January (as in a loop).

As the spin button has a min and max value, I put min as 1 (to signify January) and max as 12 (to signify December). I couldn't think of a way to loop back from December to January and vice versa.. :confused:

Appreciate if someone could help me with this. Thank you!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this for TextBox Value
Code:
Dim c As Integer
Private Sub SpinButton1_SpinDown()
c = c + 1
 c = IIf(c = 13, 1, c)
  c = IIf(c = 0, 12, c)
   TextBox1.text = MonthName(Abs(c))
End Sub
Private Sub SpinButton1_SpinUp()
c = c - 1
 c = IIf(c = 0, 12, c)
  c = IIf(c = 13, 1, c)
   TextBox1.text = MonthName(Abs(c))
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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