Audit VBA - can't get the old value to appear

scotthannaford1973

Board Regular
Joined
Sep 27, 2017
Messages
110
Office Version
  1. 2010
Platform
  1. Windows
hi

using the code below to record changes to cells in a worksheet called "Master List"; it works almost perfectly except it doesn't put the old cell value into the tracker, but instead "Empty Cell". Most of the changes to be tracked are changing text / numbers to text / numbers but it always shows the old value as "Empty Cell".

TIA!

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Sh.Name = "Master List" Then
        Dim bBold As Boolean
        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 = "Empty Cell"
        bBold = Target.HasFormula
            With Sheets("Tracker")
                '.Unprotect Password:="Secret"
                    If .Range("A1") = vbNullString Then
                        .Range("A1:e1") = Array("Sheet/Cell", "Old Value", "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
                            End If
                        .Value = Target
                        .Font.Bold = bBold
                    End With
                    .Offset(0, 3) = Date
                    .Offset(0, 4) = Application.UserName
                End With
                .Cells.Columns.AutoFit
                '.Protect Password:="Secret"
            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:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Did you step through the code and see what vOldVal was after the if statement? And by the way, vOldVal doesn't seem to be declared or defined. So, the if statement should always be true.

hi

Rich (BB code):
        If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"
        bBold = Target.HasFormula
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top