Hello liero116,
I replaced the Forms spin button with an Control Toolbox spin button.The Forms spin button updated the cell before the macro could determine which cell was to be updated. Now the current value of the cell is checked before anything is added or subtracted from it.
Private Sub SpinButton1_SpinDown()
Dim Cell As Range
Dim H As Integer
Dim Wks As Worksheet
Set Wks = Worksheets("Sheet1")
H = Hour(Now())
Set Cell = Wks.Cells(H - 6, "B")
If H >= 8 And H <= 18 Then
If Cell.Value - 1 > -1 Then Cell.Value = Cell.Value - 1
End If
End Sub
Private Sub SpinButton1_SpinUp()
Dim Cell As Range
Dim H As Integer
Dim Wks As Worksheet
Set Wks = Worksheets("Sheet1")
H = Hour(Now())
Set Cell = Wks.Cells(H - 6, "B")
If H >= 8 And H <= 18 Then Cell.Value = Cell.Value + 1
End Sub
Bookmarks