scotthannaford1973
Board Regular
- Joined
- Sep 27, 2017
- Messages
- 115
- Office Version
- 2010
- Platform
- Windows
Hi all
I have the code below which should record changes to cells in a worksheet - recording cell, old value, new value, time, date and domain name of person that made changes. It works well, except:
1. the old value is never recorded and just shows a blank. how do I record the old value (maybe the value when the workbook was opened?)
2. the code only works when individual cells are updated, so if a range is updated, it's not recorded. Is it possible to record changes to an unnamed range of cells, or just individual cells?
thanks in advance
I have the code below which should record changes to cells in a worksheet - recording cell, old value, new value, time, date and domain name of person that made changes. It works well, except:
1. the old value is never recorded and just shows a blank. how do I record the old value (maybe the value when the workbook was opened?)
2. the code only works when individual cells are updated, so if a range is updated, it's not recorded. Is it possible to record changes to an unnamed range of cells, or just individual cells?
thanks in advance
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name = "SCHEMES" Then
Dim bBold As Boolean
Dim vOldVal As String
If Target.Cells.Count > 1 Then Exit Sub
'On Error Resume Next
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
If IsEmpty(vOldVal) Then vOldVal = "Broken"
bBold = Target.HasFormula
With Sheets("AUDIT TRAIL")
'.Unprotect Password:="Secret"
If .Range("A1") = vbNullString Then
.Range("A1:e1") = Array("Sheet/Cell", "Old Value (not working)", "New Value", "Time", "Date", "User")
End If
With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
.Value = ActiveSheet.Name & " : " & Target.Address
.Offset(0, 1) = vOldVal
With .Offset(0, 2)
If bBold = True Then
.ClearComments
.AddComment.Text Text:="Scott Says:" & Chr(10) & "" & Chr(10) & "Bold values are the results of formulas"
End If
.Value = Target
.Font.Bold = bBold
End With
.Offset(0, 3) = Time
.Offset(0, 4) = Date
.Offset(0, 5) = Application.UserName
End With
.Cells.Columns.AutoFit
'.Protect Password:="TrackerL2019"
End With
vOldVal = vbNullString
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
'On Error GoTo 0
End If
End Sub
Last edited by a moderator: