Leaving Trace Precedents Turned On

by Allen Wyatt
(last updated May 17, 2018)

8

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13161) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Customized Tables of Contents

Generating a table of contents is easy in Word. Changing how that table of contents looks is also easy, provided you ...

Discover More

Clearing Everything Except Formulas

Need to get rid of everything in a worksheet except for your formulas? You can do it rather easily by applying the ideas ...

Discover More

Defeating Automatic Date Parsing

Excel is continually trying to figure out what type of data is being stored in a cell. If it can interpret a value as a ...

Discover More

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!

More ExcelTips (ribbon)

Inserting a Sound File in Your Worksheet

Some worksheets are better understood through the spoken word or with musical accompaniment. Sound files can be easily ...

Discover More

Using Check Boxes

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

Taking Pictures

Have you ever wanted to take a "picture" of a part of a worksheet and put it in another section? This tip explains how to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one less than 6?

2018-05-17 11:10:17

Chester

In the first example, why isn't there a statement just before End Sub to set ScreenUpdating to True? I understand why it is set to False just before the multitude of SetPrecedents statements.


2018-05-17 08:02:27

Col Delane

Note that tracer arrows do NOT remain visible on a worksheet indefinitely (actually, not for very long at all!) All tracer arrows disappear if you change the formula to which the arrows point, insert or delete columns or rows, delete or move cells, save the workbook (including via Autosave), among other "events".


2014-07-09 10:42:36

Patrick

Thanks Willy, that helps my understanding. Much appreciated.


2014-07-08 05:32:24

Willy Vanhaelen

The variable c stands for cell, read: For Each cell in rng.

As for the period before Cells: look in help for With Statement.


2014-07-07 13:58:38

Patrick

Just starting to experiment with VBA. Don't understand the variable c. Is the code statement interpreted as "for each range in range show precedents?" Also, why is there a period before the word Cells in the set rng statement?


2014-07-07 05:44:07

Steve Askins

Thanks Peter - that works!


2014-07-06 07:53:43

Peter

Try this
Sub ShowPrecendents3()
Dim rng As Range, c As Range
Set rng = Application.InputBox("Select or type Range", "Precendent Range", Type:=8)
For Each c In rng
c.ShowPrecedents
Next
End Sub
Sub ShowPrecendents3()


2014-07-05 07:46:42

Steve Askins

Allen,

It would be great if the range macro brought up a dialogue box (or similar) to ask the user what range (or ranges) to cover.

Is that do-able?

Happy 4th July holiday from London!


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.