Shital5757
New Member
Hi Team,
I am working on below code by which if i enter the data in column A1 it will give me the date and time in column E. After some time once i am done with the deal again I need to auto populate time stamp in column F. When we substract the time from F & E I need the average time should be auto populate in column G.
Also all the fild from E to H columns should be non editable so that user cannot change the time manually.
Kindly help me with this.
I am working on below code by which if i enter the data in column A1 it will give me the date and time in column E. After some time once i am done with the deal again I need to auto populate time stamp in column F. When we substract the time from F & E I need the average time should be auto populate in column G.
Also all the fild from E to H columns should be non editable so that user cannot change the time manually.
Kindly help me with this.
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'this should be the column ID where the date/time stamp goes
Const timeStampCol = "E" ' change as required
Const firstDataEntryRow = 4 ' assume labels in row 1
'allows you to type in rows above the data entry
'section without putting unwanted date entry there!
If Target.Row < firstDataEntryRow Then
Exit Sub
End If
'if they typed something into the timestamp cell,
'leave it alone!
If Not Application.Intersect(Target, _
Range(timeStampCol & ":" & timeStampCol)) Is Nothing Then
Exit Sub
End If
On Error GoTo RecoverFromError
Application.EnableEvents = False
'if the timestamp cell has nothing in it, put in the time stamp.
If IsEmpty(Range(timeStampCol & Target.Row)) Then
With Range(timeStampCol & Target.Row)
.NumberFormat = "mm-dd-yyyy hh:mm" ' change as desired
.Value = Now()
End With
End If
RecoverFromError:
Application.EnableEvents = True
On Error GoTo 0
End Sub
Last edited by a moderator: