Good afternoon,
I am really rubbish with VBA so please forgive my code errors. , I have a worksheet where I have a drop down list (A), once selected it puts the date and time in a cell, 2 cells to the right(C). In the same Row I have another cell(F), that if data is present, it puts the time into a cell, 2 cells to the left(D). As I add more rows, it is replicated as my list grows It was originally two separate scripts but due to an error I had to merge them. It worked for a while but now every time I click on a new Row, even with no data in (F) it puts the TIME in (D) and runs off down the page.
Can someone please help
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updated by Tucup 2017/10/12
Dim xRg As Range, xCell As Range
On Error Resume Next
If (Target.Count = 1) Then
If (Not Application.Intersect(Target, Me.Range("A:A")) Is Nothing) Then _
Target.Offset(0, 2) = Now()
Application.EnableEvents = False
Set xRg = Application.Intersect(Target.Dependents, Me.Range("A:A"))
If (Not xRg Is Nothing) Then
For Each xCell In xRg
xCell.Offset(0, 2) = Now()
Next
End If
Application.EnableEvents = True
End If
Dim rInt As Range
Dim rCell As Range
Dim tCell As Range
Set rInt = Intersect(Target, Range("F:F"))
If Not rInt Is Nothing Then
For Each rCell In rInt
Set tCell = rCell.Offset(0, -2)
If IsEmpty(tCell) Then
tCell = Time
'tCell.NumberFormat = "hh:mm"
End If
Next
End If
End Sub
I am really rubbish with VBA so please forgive my code errors. , I have a worksheet where I have a drop down list (A), once selected it puts the date and time in a cell, 2 cells to the right(C). In the same Row I have another cell(F), that if data is present, it puts the time into a cell, 2 cells to the left(D). As I add more rows, it is replicated as my list grows It was originally two separate scripts but due to an error I had to merge them. It worked for a while but now every time I click on a new Row, even with no data in (F) it puts the TIME in (D) and runs off down the page.
Can someone please help
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updated by Tucup 2017/10/12
Dim xRg As Range, xCell As Range
On Error Resume Next
If (Target.Count = 1) Then
If (Not Application.Intersect(Target, Me.Range("A:A")) Is Nothing) Then _
Target.Offset(0, 2) = Now()
Application.EnableEvents = False
Set xRg = Application.Intersect(Target.Dependents, Me.Range("A:A"))
If (Not xRg Is Nothing) Then
For Each xCell In xRg
xCell.Offset(0, 2) = Now()
Next
End If
Application.EnableEvents = True
End If
Dim rInt As Range
Dim rCell As Range
Dim tCell As Range
Set rInt = Intersect(Target, Range("F:F"))
If Not rInt Is Nothing Then
For Each rCell In rInt
Set tCell = rCell.Offset(0, -2)
If IsEmpty(tCell) Then
tCell = Time
'tCell.NumberFormat = "hh:mm"
End If
Next
End If
End Sub