Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Roll back time stamp if Workbook not saved

Status
Not open for further replies.

sterlecki

Technical User
Oct 25, 2003
181
US
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.

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
 
How would a cell be saved if the workbook is NOT saved ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Exactly what I would have expected but after testing several times the data returns to it's unsaved (previous) value while the timestamp remains.

Since changes prior to save are usually/probably stored in a buffer somewhere I assume that the timestamp is NOT buffer material but embedded in the worksheet.???

Any thoughts as to why?
 
OK problem solved upon further testing. Code in another part of the workbook was initiating a save late in the sequence.

User Error. My apologies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top