I have a sheet with 4 buttons, start, stop, reset and view leaderboard, these are command buttons 1 to 4.
The below code is supposed to make the command button 2 only visible if the entry in cells L14 and L17 is P. (Windings2 shows a 'tick' for an uppercase P).
However when I press on the 'Start@ button I get an error.
Run-time error'1004':
Method 'Range' of objet '_Worksheet' failed
The code is.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Range(L14, L17).Value = "P" Then
Me.CommandButton1.Visible = True
Me.CommandButton2.Visible = True
Me.CommandButton3.Visible = True
Me.CommandButton4.Visible = True
Else
Me.CommandButton1.Visible = True
Me.CommandButton2.Visible = False
Me.CommandButton3.Visible = True
Me.CommandButton4.Visible = True
End If
Application.ScreenUpdating = True
End Sub
The codes for the buttons are as follows
Public StopIt As Boolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("G6") = 0 Then
StartTime = Timer
PauseTime = 0
LastTime = 0
Else
StartTime = 0
PauseTime = Timer
End If
StartIt:
DoEvents
If StopIt = True Then
LastTime = TotalTime
Exit Sub
Else
FinishTime = Timer
TotalTime = FinishTime - StartTime + LastTime - PauseTime
TTime = TotalTime * 100
HM = TTime Mod 100
TTime = TTime \ 100
hh = TTime \ 3600
TTime = TTime Mod 3600
MM = TTime \ 60
SS = TTime Mod 60
Range("G6").Value = Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
If ResetIt = True Then
Range("G6") = Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
PauseTime = 0
End
End If
GoTo StartIt
End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
StopIt = True
End Sub
Private Sub CommandButton3_Click()
Call Add_time_to_Leaderboard
Range("G6").Value = Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime = 0
ResetIt = True
Call Macro1
End Sub
Private Sub CommandButton4_Click()
Sheet2.Visible = True
Sheets("Leaderboard").Select
Sheet1.Visible = False
End Sub
Any help appreciated.
Bookmarks