I'm trying to write excel vba and result is half-way working.
Its intention is to enter a date/timestamp in column C for respective row in column B. This occurs when clicking on any cell in column B. It is suppose to do this for columns D and E where E is the date/time entry for any cell clicked on in column D. EXAMPLE... If I click on cell B5, date/time stamp should appear in C5. If I click on cell D20, a date/timestamp should appear in C20. I hope this helps you to understand.***ALSO, Top Row is a lable, like A1 has word Task#, B1 has word like StepsToDo, C1 has word like Time4Steps,... I want Top Row to not accept any new text - protected ***.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iRange As Range
If Target.Cells.Count <> 1 Then Exit Sub
Set iRange = Intersect(Target, Range("B:B"))
If iRange Is Nothing Then Exit Sub
Application.EnableEvents = False
Range("C" & Target.Row).Value = Now()
Application.EnableEvents = True
Dim xRange As Range
If Target.Cells.Count <> 1 Then Exit Sub
Set xRange = Intersect(Target, Range("D:D"))
If xRange Is Nothing Then Exit Sub
Application.EnableEvents = False
Range("E" & Target.Row).Value = Now()
Application.EnableEvents = True
End Sub