by Allen Wyatt
(last updated August 24, 2019)
Gavin has a large worksheet that he works with, and he finds it helpful to use the Trace Precedents tool (on the Formulas tab of the ribbon) to figure out what is going on. Gavin would like the setting of the tool to be "turned on" even when he saves the workbook, but Excel doesn't let him do this. He wonders if there is a way to leave it turned on so that the precedents are always marked in the workbook.
One would think that it should be relatively easy to turn on the precedents, via macro, when you open a workbook. All you need to do is use a macro like the following:
Sub ShowTracePrecendents1() Dim rng As Range Dim c As Range With ActiveSheet.UsedRange Set rng = .Cells.SpecialCells(xlCellTypeFormulas, 23) End With Application.ScreenUpdating = False For Each c In rng c.ShowPrecedents Next End Sub
The macro determines which cells in the worksheet contain formulas (only formula-containing cells can have precedents) and then steps through each of those cells, turning on the display of the precedents.
The problem, of course, is that this approach doesn't do exactly what Gavin wanted. It is probable that Gavin, when working with his data, doesn't turn on the precedents for every single cell, but only for some of the cells. The macro turns on precedent display for all possible cells in the worksheet. If you only want to display the precedents for some cells, you need to specify the cells in the macro.
Sub ShowTracePrecendents2() Dim rng As Range Dim c As Range Set rng = Range("G1:G5,G7:G8") For Each c In rng c.ShowPrecedents Next End Sub
In order to use the macro effectively, you would need to change the line that sets the rng variable so that it references the cells for which you want precedents displayed.
Regardless of which macro you go with, you can create an "auto open" macro (as discussed in other ExcelTips) that will run it automatically whenever the workbook is opened.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13161) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Check boxes, just like those used in Windows dialog boxes, can be a great addition to a worksheet. Here's how to add them ...Discover More
If the information you import into Excel is treated as text by the program, you may want to convert it to numeric values. ...Discover More
The primary way to extend what Excel can do is through the use of add-ins. This tip explains what they are and the ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.