Overview
Formula auditing is essential for verifying spreadsheet integrity. These VBA macros enhance Excel's built-in tracing capabilities by adding safety checks for large dependency networks and a quick toggle for R1C1 reference style.
Trace_Dependents and Trace_Precedents show arrow trails for the selected cells, with a confirmation prompt when more than 200 arrows would be created. Toggle_R1C1 switches between A1 and R1C1 reference styles with a single click.
How It Works
- Trace_Dependents: Iterates through each selected cell and calls ShowDependents, drawing blue arrows to all cells that depend on the selection. Prompts for confirmation if more than 200 arrows would be created
- Trace_Precedents: Works in reverse, drawing arrows from cells that feed into the selected formulas. Same safety threshold applies
- Toggle_R1C1: Switches the global Application.ReferenceStyle between xlA1 and xlR1C1, useful for auditing formula patterns across large ranges
The VBA Code
Public Sub Trace_Dependents()
Dim Cel As Range
Dim i As Integer: i = 0
On Error Resume Next
i = Selection.DirectDependents.Count
On Error GoTo 0
If i > 200 Then
If MsgBox("This action will create " & i & " active Dependents arrows. Are you sure?", vbYesNo) = vbNo Then Exit Sub
End If
For Each Cel In Selection: Cel.ShowDependents: Next Cel
End Sub
Public Sub Trace_Precedents()
Dim Cel As Range
Dim i As Integer: i = 0
On Error Resume Next
i = Selection.DirectPrecedents.Count
On Error GoTo 0
If i > 200 Then
If MsgBox("This action will create " & i & " active Precedents arrows. Are you sure?", vbYesNo) = vbNo Then Exit Sub
End If
For Each Cel In Selection: Cel.ShowPrecedents: Next Cel
End Sub
Public Sub Toggle_R1C1()
If Application.ReferenceStyle = xlA1 Then
Application.ReferenceStyle = xlR1C1
Else
Application.ReferenceStyle = xlA1
End If
End Sub
Final Thoughts
These small but focused utilities make formula auditing faster and safer. The arrow-count threshold prevents Excel from freezing on large dependency networks, and the R1C1 toggle is invaluable for spotting formula inconsistencies across rows and columns.