Hi all!
I have a user form with lots of text boxes and spin buttons that work as a time picker. So one textbox shows value of spin button (from -1 to 25) for hours and other one shows value between -1 and 60 for minutes.
Each of this spin buttons contains the same code:
For hours:
For minutes:
I have about 30 of these spin buttons (15 for hours and 15 for minutes), so I wonder if it is possible to create Public Sub or Function with this code and call it for each button change even, passing information like Button name and TextBox name?
I have a user form with lots of text boxes and spin buttons that work as a time picker. So one textbox shows value of spin button (from -1 to 25) for hours and other one shows value between -1 and 60 for minutes.
Each of this spin buttons contains the same code:
For hours:
VBA Code:
Private Sub SpinButton1_Change()
If Me.SpinButton1.Value = 24 Then Me.SpinButton1.Value = 0
If Me.SpinButton1.Value = -1 Then Me.SpinButton1.Value = 23
Me.TXT1.Value = Format(Me.SpinButton1.Value, "00")
End Sub
For minutes:
VBA Code:
Private Sub SpinButton2_Change()
If Me.SpinButton2.Value = 60 Then Me.SpinButton2.Value = 0
If Me.SpinButton2.Value = -1 Then Me.SpinButton2.Value = 59
Me.TXT2.Value = Format(Me.SpinButton2.Value, "00")
End Sub
I have about 30 of these spin buttons (15 for hours and 15 for minutes), so I wonder if it is possible to create Public Sub or Function with this code and call it for each button change even, passing information like Button name and TextBox name?