G
Guest
Hello
I have a worksheet with a vba time stamp code (as below). The problem is
that I want the time to be stamped not when the cell changes as it is now,
but when the changes are saved. Is there any way I can do this?
I tried changing the name of the event to Private Sub
Worksheet_BeforeSave(ByVal Target As Range), but it didn't work.
Any help would be greatly appreciated!
My current vba code is:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim c As Range
For Each c In ActiveSheet.Range("J4:J1999")
If c = "e11 - Document ready" Then
If Target.Count > 1 Then Exit Sub
On Error GoTo ErrHandler
Set rng = Range("J4:J1999")
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
Target.Offset(1997, 27).Value = Date
Target.Offset(1997, 27).NumberFormat = "dd-mmm-yy"
Target.Offset(1997, 27).EntireColumn.AutoFit
End If
End If
If c = "e10 - Approval ongoing" Then
If Target.Count > 1 Then Exit Sub
On Error GoTo ErrHandler
Set rng = Range("J4:J1999")
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
Target.Offset(1997, 26).Value = Date
Target.Offset(1997, 26).NumberFormat = "dd-mmm-yy"
Target.Offset(1997, 26).EntireColumn.AutoFit
End If
End If
'etc
ErrHandler:
Application.EnableEvents = True
Next c
End Sub
I have a worksheet with a vba time stamp code (as below). The problem is
that I want the time to be stamped not when the cell changes as it is now,
but when the changes are saved. Is there any way I can do this?
I tried changing the name of the event to Private Sub
Worksheet_BeforeSave(ByVal Target As Range), but it didn't work.
Any help would be greatly appreciated!
My current vba code is:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim c As Range
For Each c In ActiveSheet.Range("J4:J1999")
If c = "e11 - Document ready" Then
If Target.Count > 1 Then Exit Sub
On Error GoTo ErrHandler
Set rng = Range("J4:J1999")
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
Target.Offset(1997, 27).Value = Date
Target.Offset(1997, 27).NumberFormat = "dd-mmm-yy"
Target.Offset(1997, 27).EntireColumn.AutoFit
End If
End If
If c = "e10 - Approval ongoing" Then
If Target.Count > 1 Then Exit Sub
On Error GoTo ErrHandler
Set rng = Range("J4:J1999")
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
Target.Offset(1997, 26).Value = Date
Target.Offset(1997, 26).NumberFormat = "dd-mmm-yy"
Target.Offset(1997, 26).EntireColumn.AutoFit
End If
End If
'etc
ErrHandler:
Application.EnableEvents = True
Next c
End Sub