Results 1 to 7 of 7

audit log VBA code not capturing IF formula result

Threaded View

  1. #1
    Registered User
    Join Date
    05-21-2009
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    4

    audit log VBA code not capturing IF formula result

    I have an audit log VBA code, to capture changes from several worksheets into one worksheet called "LRLog".

    This only writes value changes. Formatting changes are not required to be captured.

    The VBA code works fine, but does NOT capture changes in those cells which are determined by IF formula based on data input in other cells.

    Users will make changes in columns C, D, E, F, and H, with IF formula in columns A and G showing a result, dependent on the data input in columns D, E, and F.
    However, currently, any changes to cols A or G (because of the outcome of formulae in col A or G) are not captured in the audit log, as attached:
    (yellow blocks in the attached Audit log are what is expected should be displayed).

    The following VBA has been used in the sheets where changes will take place.
    ------------------------------------------
    Dim PreviousValue As Variant
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Errb As Integer
        On Error GoTo ErrTrap:
        If Target.Value <> PreviousValue Then
          With Sheets("LRlog").Cells(65000, 1).End(xlUp)
            .Offset(1, 0).Value = Application.UserName
            .Offset(1, 1).Value = ActiveSheet.Name
            .Offset(1, 2).Value = "changed cell"
            .Offset(1, 3).Value = Target.Address
            .Offset(1, 4).Value = "from"
    
            .Offset(1, 5).Value = PreviousValue
            .Offset(1, 6).Value = "to"
            .Offset(1, 7).Value = Target.Value
            .Offset(1, 8).Value = "on"
            .Offset(1, 9).Value = Format(Date, "d/mmm/yyyy")
            .Offset(1, 10).Value = Format(Now(), "hh:mm:ss")
            
                   
          End With
        End If
        Exit Sub
    ErrTrap:
      ErrNum = Err
      
      If ErrNum = 13 Then
        '*** Multiple cells have been selected, treat them as one merged group*****
        Resume Next
      End If
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        PreviousValue = Target.Value
    End Sub
    ------------------------------------

    Can anyone help with the VBA code so that any changes to cols A or G (because of the outcome of formulae in col A or G) are also captured in the audit log?

    I would also like to include good error handling in this project if possible.
    Attached Files Attached Files
    Last edited by AliGW; 04-12-2018 at 04:41 AM. Reason: Code tags added - you must do this yourself in future, please.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Unique counter based on the location code and time of an audit
    By quentin5000 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-02-2018, 04:00 AM
  2. VBA code for audit trail issue
    By TheGrinch1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2015, 08:06 AM
  3. Assistance with Audit code...
    By ciresuark in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-26-2015, 01:26 PM
  4. [SOLVED] Code result wrong but formula correct result
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-11-2014, 12:26 PM
  5. VBA code for Audit schedule email-weekly
    By Hense in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2012, 04:42 AM
  6. Web Query - Submitting Data and Capturing Result
    By Ben in forum Excel General
    Replies: 1
    Last Post: 04-29-2012, 10:12 AM
  7. stock audit & bar code scanner
    By joemahony in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-28-2008, 12:53 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1