Hi All,
Just a simple question, I'm using the following code (gained from a search on this forum) to great effect on a spreadsheet.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
'Update date-time stamp when a job is set in column A
If Not Intersect(Range("a3:a200"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 4).ClearContents
Else
If .Offset(0, 11).Value = "" Then
With .Offset(0, 11)
.NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
.Value = Now
End With
End If
End If
Application.EnableEvents = True
'Update date-time stamp when job is completed in column I
ElseIf Not Intersect(Range("i3:i200"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 3).ClearContents
.Offset(0, 4).ClearContents
Else
With .Offset(0, 4)
.NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
.Value = Now
End With
'Calculate job duration in column N
.Offset(0, 5).NumberFormat = "hh:mm:ss"
.Offset(0, 5) = .Offset(0, 4) - .Offset(0, 3)
End If
Application.EnableEvents = True
End If
End With
End Sub
What I'd like to do now is add another auto date/time stamp into the routine so that an entry in column H triggers it.
I tried copying the first routine (for column A) but get an error.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
'Update date-time stamp when a job is set in column A
If Not Intersect(Range("a3:a200"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 4).ClearContents
Else
If .Offset(0, 11).Value = "" Then
With .Offset(0, 11)
.NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
.Value = Now
End With
End If
End If
Application.EnableEvents = True
'Update date-time stamp when a job is set in column H
If Not Intersect(Range("h3:h200"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 4).ClearContents
Else
If .Offset(0, 7).Value = "" Then
With .Offset(0, 7)
.NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
.Value = Now
End With
End If
End If
Application.EnableEvents = True
'Update date-time stamp when job is completed in column I
ElseIf Not Intersect(Range("i3:i200"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 3).ClearContents
.Offset(0, 4).ClearContents
Else
With .Offset(0, 4)
.NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
.Value = Now
End With
'Calculate job duration in column N
.Offset(0, 5).NumberFormat = "hh:mm:ss"
.Offset(0, 5) = .Offset(0, 4) - .Offset(0, 3)
End If
Application.EnableEvents = True
End If
End With
End Sub
Am I best off using a completely separate piece of code, or can I insert another sub-routine into this one?
Thanks,
Gavin.
Bookmarks