Reputation: 21
I am using the following as a timestamp. I would like a button to disable it (so that I can edit without it recording times) and a button to enable it again.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.column = 12 And Target.Row = 9 Then
If Target.Value = "" Then
Target.Offset(0, 4).Value = ""
Else
Target.Offset(0, 4).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
ElseIf Target.column = 12 And (Target.Row >= 10 And Target.Row <= 600) Then
If Target.Value = "" Then
Target.Offset(-1, 5).Value = ""
Else
Target.Offset(-1, 5).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
End If
End Sub
Upvotes: 1
Views: 61
Reputation: 228
Use a button which will update cell ZZ200(or as per your choice) with value "ON" or "OFF" and the put your code inside the condition as below :
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("Sheet1").Range("ZZ200").Value = "ON" Then
If Target.Column = 12 And Target.Row = 9 Then
If Target.Value = "" Then
Target.Offset(0, 4).Value = ""
Else
Target.Offset(0, 4).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
ElseIf Target.Column = 12 And (Target.Row >= 10 And Target.Row <= 600) Then
If Target.Value = "" Then
Target.Offset(-1, 5).Value = ""
Else
Target.Offset(-1, 5).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
End If
End If
End Sub
Upvotes: 0
Reputation: 8531
use a toggle button, returns true or false, then have the 1st line,if togglebutton then exit sub
Upvotes: 2