Outlining Cells Referenced in a Formula

by Allen Wyatt
(last updated February 22, 2020)

4

When Fraser selects a cell that contains a formula and then clicks in the Formula bar, any cells referenced in the formula are outlined in different colors. This makes Fred wonder if it is possible to outline cells in this manner without the need to click in the Formula bar. He would find it helpful to have the outlining just when a cell is selected.

Your first thought might be that you could create a macro to do what Fraser wants. The problem is, the macro would be quite complex, as it would need to evaluate the contents of the cell and then provide the desired outlining. (Figuring out which colors to use would be a headache, plus you couldn't highlight the cell references in the formulas in color.) Also, there needs to be a way to remove the outlining when moving to a different cell. Finally, when you are in Edit mode (as when you click in the Formula bar), then all bets are off because you can't run macros.

No, it is simpler to remember what is happening when you click in the Formula bar—as already mentioned, you are putting Excel into Edit mode so that you can edit the contents of the cell. There are two very common ways to switch to Edit mode: click in the Formula bar (as Fraser did) or simply press F2. Thus, a quick way to see the outlining that Fraser enjoys would be to press F2. When done, press Esc and Edit mode is exited.

It is possible, of course, to use a macro to kick you into Edit mode whenever you select a cell. Here's an example of one that will do it:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
  ByVal Target As Range)
    If Target.HasFormula Then
        Application.SendKeys ("{F2}")
    End If
End Sub

The macro, which should be stored in the ThisWorkbook module, implements an event handler that is executed every time the selection changes. The code then checks to see if the cell contains a formula, and if it does, then the F2 key is stuffed into the keyboard buffer and Excel goes into Edit mode. This macro effectively automates the manual pressing of the F2 key. (Personally, for me, I would find it easier to just press F2 in those instances when I want to look at the outlining.)

There is another thing you might find helpful. Excel has this obscure little feature that allows you to select the cells referenced in a formula. To see how this works, select the cell containing the formula and then press Ctrl+[ (that's the left bracket). You should see that Excel creates a selection set that consists of the cells referenced in the formula. Since this is actually a selection set, the original cell you were in (the one containing the formula) is no longer selected.

On our Office 365 systems, the same effect is attained by simply double-clicking on the cell containing the formula. On older versions of Excel, double-clicking a cell may result in actually going into Edit mode instead of creating the selection set from the formula in the cell.

Finally, you can also use the auditing tools in Excel to see which cells are related to the current cells. Describing how to use all of the auditing tools is beyond the scope of this tip, but you can explore them by displaying the Formulas tab of the ribbon and working with the tools in the Formula Auditing group.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7336) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

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

Setting a Default for the Object Browser

Does it bother you that when you press Ctrl+Page Up or Ctrl+Page Down you aren't always taken to the top of the previous ...

Discover More

Changing Print Dialog Box Defaults

Some of the built-in defaults in Word can't be changed. Often times, however, you can work around these defaults by using ...

Discover More

Testing for an Empty Worksheet

If you are using a macro to process a number of worksheets, you may have a need to know if the worksheet is empty or not. ...

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)

Counting Non-Blank Cells

Need to count the number of cells in a range that are not blank? You can use the COUNTA function of a more complex ...

Discover More

Returning Zero When a Referenced Cell is Blank

Reference a cell in a macro, and if that cell is blank Excel normally equates that to a zero value. What if you don't ...

Discover More

Combining Numbers and Text in a Cell

There are times when it can be beneficial to combine both numbers and text in the same cell. This can be easily done ...

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 seven minus 5?

2020-02-24 14:17:33

1695814

This might not be exactly what you're looking for, but ctrl+tilde (ctrl+`) will display the cells' formulas instead of results. When a cell is selected it will highlight in various colors, the other cells used.


2020-02-23 03:03:21

Thomas Papavasileiou

A small addition to Ron S, plus a comment to John Mann's posts

Typing Ctrl+{ is equivalent to trace precedents command, typing Ctrl+Shift+{ is equivalent to second level trace precedents.

Using } instead of { has the same type of behavior as the trace dependents

All of the above select the dependents or precedents and can be formatted with a single command

I think that John Mann's impression is the correct one.

Hope that Fraser's question is answered


2020-02-22 15:32:45

John Mann

I get the impression that Fraser is looking for a simple way of achieving the marking of reference cells. I f he is initially selecting the cell with the formula using the mouse(likley since he then clicks the formula bar). then there is a very easy way to semi-automaiically colour mark the referenced cell. Instead of clicking the formula cell to select it, double-click the cell. Tbis will both select the cell in question and cause the referenced cells to be marked. If you have you mouse set up so that an extra button is programmed as double-click, then there won't even be any extra finger moveents ( I have the centre button/scroll wheel set that way). I tested this using Excel 2010


2020-02-22 13:33:53

Ron S MVP

Just found this other article that does something similar to this request

Highlight all cells referenced by a formula in Excel?
https://www.extendoffice.com/documents/excel/4292-excel-highlight-cells-referenced-in-formula.html
This article is talking about highlighting all cells which was referenced by a formula in Excel. Please follow the below two methods to get it done.
. * Highlight all cells referenced by a formula with Shortcut key
. * Highlight all cells referenced by a formula with VBA code
.


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.