Tracking formula changes with VBA code

coreyalaurence39

New Member
Joined
Mar 10, 2022
Messages
20
Office Version
  1. 2019
Platform
  1. Windows
VBA Code:
Option Explicit
Public OldData
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target, Range("A5:P1000,I2,L2,P2")) Is Nothing Then OldData = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target, Range("A5:P1000")) Is Nothing Then
        Application.ScreenUpdating = False
        Sheets("Log Details").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = Array(Environ("UserName"), Target.Address, OldData, Target.Value, Now())
    Else
        If Intersect(Target, Range("I2,L2,P2")) Is Nothing Then Exit Sub
        Application.ScreenUpdating = False
        Select Case Target.Column
            Case Is = 9
                Sheets("DispatcherTracking").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = Array(Environ("UserName"), Target.Address, OldData, Target.Value, Now())
            Case Is = 12
                Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = Array(Environ("UserName"), Target.Address, OldData, Target.Value, Now())
            Case Is = 16
                Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = Array(Environ("UserName"), Target.Address, OldData, Target.Value, Now())
        End Select
    End If
    Application.ScreenUpdating = True
End Sub

I would like to add the function of tracking when a formula is changed in the sheet to the above code. I would like to know what the old formula was and what it has been changed too. I am not sure how to add this functionality to the above code.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.
Be sure to follow & read the link at the end of the rule too!

It appears that this is the same question as posted in a number of other forums. Please provide links to all threads where you have posted this in other forums.

If you cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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