I have a worksheet that puts a timestamp in column 16 if any column in that row is changed. If a user decides to delete data for any of these columns then the timestamp is deleted.
My problem is when a user changes a cell and then decides NOT to save the changes the data cells are of couse not saved however the timestamp in column 16 is saved.
Is there a way to roll this timestamp column back to it's original value or return it to blank if the workbook is not saved?
Much of this code is from a post that I previously found on Tek-Tips but cannot remember the thread number or whom to credit.
My problem is when a user changes a cell and then decides NOT to save the changes the data cells are of couse not saved however the timestamp in column 16 is saved.
Is there a way to roll this timestamp column back to it's original value or return it to blank if the workbook is not saved?
Much of this code is from a post that I previously found on Tek-Tips but cannot remember the thread number or whom to credit.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Sheets("Data").Range("R1").Value = "Changed - " & Now()
' this sub adds a timestamp on the row where data was entered
Dim intRow, intCol, intTimeCol As Integer ' target row and column, and timestamp column
Dim TargetCell As Range
' check to see if target cell is in the input portion of the worksheet
For Each TargetCell In Target
' check to see if target cell is in the input portion of the worksheet
If (TargetCell.Row >= 2) And (TargetCell.Row <= 1500) Then
' check to see if target column is A thru O
If (Target.Column >= 1) And (Target.Column <= 15) Then
'time stamp column is column P
intTimeCol = 16
intCol = 1
' check to see if the target cell is empty and that column A is populated
If TargetCell.Text <> "" And Cells(TargetCell.Row, intCol) <> "" Then
Cells(TargetCell.Row, intTimeCol).Value = Now() ' add timestamp to target row
Else
Cells(TargetCell.Row, intTimeCol).Value = "" ' delete timestamp if target cell is empty
End If
End If
End If
Next
End Sub