I am looking for two Private Sub Worksheet_Change for one sheet.
I need these to both to work, but can only get the first one to work.
Is there a way to get these to work by combining them somehow?
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C4:C6")) Is Nothing Or Target.Value <> True Then Exit Sub
Debug.Print Target.Address
Dim HypTime As Date
Dim StartTime As Date, EndTime As Date
' get time period for changes
StartTime = Range("F1").Value
EndTime = Range("F2").Value
'set criteria met time
HypTime = Format(Now(), "hh:mm")
If (HypTime >= StartTime) And (HypTime <= EndTime) Then
' if True added between start and end times, add 1 to Number of Counts and record time
Cells(Target.Row, 6) = Cells(Target.Row, 6) + 1
Cells(Target.Row, 7) = HypTime
End If
End Sub
If Intersect(Target, Range("E4:E6")) Is Nothing Or Target.Value <> True Then Exit Sub
Debug.Print Target.Address
Dim HypTime As Date
Dim StartTime As Date, EndTime As Date
' get time period for changes
StartTime = Range("F1").Value
EndTime = Range("F2").Value
'set criteria met time
HypTime = Format(Now(), "hh:mm")
If (HypTime >= StartTime) And (HypTime <= EndTime) Then
' if True added between start and end times, add 1 to Number of Counts and record time
Cells(Target.Row, 9) = Cells(Target.Row, 9) + 1
Cells(Target.Row, 10) = HypTime
End If
End Sub
Excel 2019 and Windows 10
Thanks
I need these to both to work, but can only get the first one to work.
Is there a way to get these to work by combining them somehow?
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C4:C6")) Is Nothing Or Target.Value <> True Then Exit Sub
Debug.Print Target.Address
Dim HypTime As Date
Dim StartTime As Date, EndTime As Date
' get time period for changes
StartTime = Range("F1").Value
EndTime = Range("F2").Value
'set criteria met time
HypTime = Format(Now(), "hh:mm")
If (HypTime >= StartTime) And (HypTime <= EndTime) Then
' if True added between start and end times, add 1 to Number of Counts and record time
Cells(Target.Row, 6) = Cells(Target.Row, 6) + 1
Cells(Target.Row, 7) = HypTime
End If
End Sub
If Intersect(Target, Range("E4:E6")) Is Nothing Or Target.Value <> True Then Exit Sub
Debug.Print Target.Address
Dim HypTime As Date
Dim StartTime As Date, EndTime As Date
' get time period for changes
StartTime = Range("F1").Value
EndTime = Range("F2").Value
'set criteria met time
HypTime = Format(Now(), "hh:mm")
If (HypTime >= StartTime) And (HypTime <= EndTime) Then
' if True added between start and end times, add 1 to Number of Counts and record time
Cells(Target.Row, 9) = Cells(Target.Row, 9) + 1
Cells(Target.Row, 10) = HypTime
End If
End Sub
Excel 2019 and Windows 10
Thanks