Link Chart Text to a Cell
by Jon Peltier
Wednesday, June 4th, 2008
Peltier Technical Services, Inc., Copyright © 2010.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
A very common question I am asked is, “How do I link text on a chart to text in a cell?” This is really not too difficult, but it’s also not intuitive. Except for axis tick labels, text elements in an Excel chart can be linked to worksheet cells. These text elements include the chart title, axis titles, data labels, and shapes.
To link a text element to a cell, you first must create the text element, using a temporary unlinked label. (Technically a data label is linked to something outside the chart if you use one of the standard options, such as series name, values, or labels, but these are not formulaic links.)
The screen shot below shows a chart, the chart source data range B15:C22, and several labels in columns D and E which will be applied to the chart. You can also see the Name Box in the top left, which usually identifies the selected object, and the Formula Bar to the right of the Name Box.

Link Chart and Axis Titles
Start by linking the title to a cell. A chart with one series uses the series name as the chart title. Select the chart title, and the Name Box shows Chart Title.

Click in the Formula Bar, type =, then click on the cell you want to link to, or type the fully referenced address of the cell. Actually the click in the formula bar is unnecessary, as Excel activates the formula bar when any key is clicked. The link formula appears in the Name Box, and the linked cell is highlighted with the marching ants border.

Press Enter. The chart title updates to show the contents of the selected cell. If the cell contents are changed, the chart title will change accordingly.

Use the same protocol twice more to customize the X and Y axis titles.

Link Data Labels
If you are going to link one or two labels, use the protocol shown here. If you are going to link whole series at a time, this protocol becomes tedious very quickly. Fortunately this can be automated through VBA, and there are several utilities around the internet that do this for you. Two good ones (and free ones) are Rob Bovey’s Chart Labeler and John Walkenbach’s Chart Tools. They install quickly and interface smoothly with Excel.
Add a data label to the first point in the series. Select the series with one click, then select the point with another click. Press CTRL+1 (numeral one) to open the Format Point dialog. Select any of the label options, such as Series Name.

The label has been moved from its default Right position to Above. Select the series of labels with one click, then select the specific label with another click. If the Name Box were wider it would display "Alpha" Point "1" Data Label.

Click in the Formula Bar (optional), type =, and click on the cell you want to link to the data label. The link formula appears in the Name Box, and the linked cell is highlighted with the marching ants border.

Press Enter and the data label updates. Add a data label to the last point in the series, and link it to a cell using this process.

Link Shapes
Linking a shape to a cell is a bit trickier. Start by adding a shape to the chart (here the shape is an oval).

Type =, click on the cell that contains the text you want to display in the shape. The link formula appears in the Name Box, and the linked cell is highlighted with the marching ants border.

Press Enter, and if you’re using Excel 2007, the shape picks up the link. Here’s where there’s a bug in earlier versions of Excel. Instead of the selected shape picking up the link, Excel adds a new textbox with the link. Delete the textbox.

A link can be added to the shape using VBA, so I wrote a short procedure to make it happen. Copy this code and paste it into a regular code module (see How To: Use Someone Else’s Macro if you are not familiar with this). Select the shape and run the following procedure.
Sub LabelSelectedShape()
Dim rng As Range
Set rng = Application.InputBox(Type:=8, _
Prompt:="Select the cell with the intended label for the selected shape.")
With Selection
.Formula = "=" & rng.Address(External:=True)
End With
End Sub

Select a cell and click Okay. The oval has been linked to the cell.

Link Formula
Any formula in a chart text element must be a link formula, that is, the formula can only link to a cell or range (including a named range). You cannot write a formula that uses any functions. If you have text in cells A1 and B1, and you want your text element to use the formula ="the fraction is "&A1&"/"&B1, you have to commandeer another cell, say, cell C1, and enter your formula in that cell, then link the text element to the cell with the formula.
Related Posts:
- Callout Labels with XY Line Segments
- Fill Below an XY Chart Series (XY-Area Combo Chart)
- Fill Between XY Chart Series (XY-Area Combo Chart)
- How To: Assign a Macro to a Button or Shape
- UDF to Calculate an Arbitrary Formula
- Regular Charts from Pivot Tables
- Display One Chart Dynamically and Interactively
- Growth Rates in a Panel Chart
- Magazine Quality Chart (Economist)
- Individually Formatted Dual Category Labels
Posted: Wednesday, June 4th, 2008 under Formatting.
Comments: 25
Comments
Comment from Tim Mayes
Time: Friday, June 6, 2008, 1:00 am
Thanks for this Jon. This is an incredibly useful technique, and an underused one. I use it most commonly for chart titles since it allows me to dynamically build the title in a cell. That way I can use the sheet as a template and the chart title will always be correct when I change the data.
Also, you can insert “floating” text (I don’t know what else to call it, but it isn’t connected to anything). In Excel 2003 just select the chart and press = and then select a cell. In Excel 2007, you have to first insert a textbox into the chart and then use the textbox.
One other tip is using the Text() function when building strings to use. This allows you to construct strings that have dynamic numbers in them, and you control the number format.
Comment from Jon Peltier
Time: Friday, June 6, 2008, 7:39 am
Tim -
The “floating” text is simply a textbox. If the chart is selected and you start typing, the text goes into the formula bar. This text is placed in a textbox when you press Enter. If the text is a link formula, the textbox is linked.
Too many people ended up with random textboxes in their charts without knowing why, so Microsoft changed the behavior. In Excel 2007 you need to explicitly add the textbox first. The formula bar still collects your keystrokes, but they are discarded.
I use the F4 key a lot when editing a lot of charts. Sometimes I wonder why the F4 key didn’t do what I expected. Lately I notice that when it doesn’t work in 2003, it’s because I typed 4 instead of F4, and I get a textbox that contains “4″. In 2007 when F4 doesn’t work, I groan because it’s how 2007 was designed.
Comment from Michel
Time: Sunday, June 8, 2008, 3:37 pm
I used a similar technique to have multilingual charts.
With a Choose command, I let the user (me) choose the language and all titles follow…
Comment from Jon Peltier
Time: Sunday, June 8, 2008, 6:38 pm
And when the number of languages and phrases becomes too large for CHOOSE, you can use INDEX or VLOOKUP
Comment from Sandi Mays
Time: Monday, June 9, 2008, 2:49 pm
I thought I knew everything about Excel, but never came across this tip. Thank you for posting!
Comment from Orhan Karsligil
Time: Friday, July 18, 2008, 2:16 pm
In Excel 2007 the text box with formula does not automatically change when the referenced cell changes if the file has been opened and saved by Excel 2003 previously.
Comment from Jon Peltier
Time: Friday, July 18, 2008, 2:19 pm
Orhan -
Thanks for describing this glitch. I’ve heard people complain about the problem (or something similar), but nobody noticed the saving is 2003 part. When the file is saved in 2007 are the links fixed?
Comment from Mark
Time: Monday, August 4, 2008, 12:34 pm
I’ve been doing this for years in Excel 2003. Last week, I upgraded to Office 2008, and all my embedded formulas have disappeared from my charts. I’m not happy with the upgrade.
I can get the embedded formula to work in a new Excel 2008 spread sheet, but my old 2008 spreadsheets refuse to display them.
Comment from Jon Peltier
Time: Monday, August 4, 2008, 1:39 pm
Mark – 2008? You switched to a Mac too? My condolences. Or did you mean 2007?
I’ve heard of these links not surviving the upgrade from 2003 to 2007, but have not experienced it personally. The links seem to work fine in charts created in 2007.
Comment from leroy
Time: Friday, August 8, 2008, 10:40 pm
How can I get the my values to display when using the % as part of the data label in a bar chart?
Comment from Gaetan
Time: Tuesday, August 19, 2008, 10:22 am
John and Orhan -
I’m not 100% sure of this code, but this seems to work ok on a big project to solve the “saved in 2003 and open in 2007″ issue:
Sub xl_2007_recreate_link_images_cells()
Dim sh As Worksheet
Dim shp As Shape
Dim t As String
For Each sh In ThisWorkbook.Sheets
For Each shp In sh.Shapes
If shp.Type = msoTextBox Or shp.Type = 1 Then
t = shp.DrawingObject.Formula
If Right(t, 1) = " " Then t = Left(t, Len(t) - 1)
If t <> "" Then
shp.DrawingObject.Formula = t
End If
End If
Next
Next
End Sub
That said, i don’t know why the shp.DrawingObject.Formula add a space at the end.
Gaetan
Comment from Jon Peltier
Time: Tuesday, August 19, 2008, 11:00 am
Gaetan –
I don’t know why it works, either, or why the trailing space should matter. Perhaps something as simple as
shp.DrawingObject.Formula = shp.DrawingObject.Formula
is all that’s really needed.
Comment from Gaetan
Time: Tuesday, August 19, 2008, 11:16 am
Jon –
Thks for your reply
That was of course my first idea, but it happened not to work with names because of an added space at the end… very weird…
If I well remember, it works well with normal reference (=A1)
Comment from Kathy
Time: Saturday, October 18, 2008, 4:18 am
I’ve been using this technique successfully for a while, but I have come across two PCs (Excel 2007) where you can’t do this. Typing = into the chart title etc just displays = and clicking on a cell just deselects the chart. Same chart on another machine (being updated by the same person) works fine. Any ideas?
Comment from Jon Peltier
Time: Saturday, October 18, 2008, 9:52 am
2007 makes it a bit harder to add labels accidentally. You have to make sure the text element itself is selected, but the cursor is not seen in the text itself, nor is any of the text selected.
If you have done this and it still isn’t working, I don’t know why, because I haven’t had this problem.
Comment from Rebecca
Time: Tuesday, November 18, 2008, 10:41 pm
Thank you! This is exactly what I needed!
Comment from Marty
Time: Tuesday, October 13, 2009, 6:07 pm
I’m not sure if this is a Excel 2007 issue, but the example code works well for text boxes or other created shapes, but doesn’t work if I have an axis label or chart title selected. Instead, I get a Runtime 438, not supported.
It wouldn’t be too bad if I could record a macro, but I’m using 2007 and it ignores moste verything I do with charts. What I’m really after is VBA code to set an axis title formula to reference a cell. Any suggestions? Impossible?
Comment from Jon Peltier
Time: Tuesday, October 13, 2009, 8:41 pm
Marty -
The code only works for shapes. I added the code because the old way of selecting the shape and entering a formula in the formula bar doesn’t work in 2007. The manual way of adding linked labels to other chart text elements works as in 2003.
This code programmatically links the X and Y axis titles to cells:
ActiveChart.Axes(xlCategory).AxisTitle.Text = “=Sheet1!R2C1″
ActiveChart.Axes(xlValue).AxisTitle.Text = “=Sheet1!R2C2″
Comment from Marty
Time: Wednesday, October 14, 2009, 10:33 am
Jon,
Worked beautifully. Thank you very much. Part of my trouble was that I am using two charts on one chart sheet and Excel won’t let me click on the axis and assign it to a cell. I can do that if there is a single chart on the chart sheet, but not if I have two chart objects embedded. Not really sure why that is.
Man, my charts have come a long way since discovering this excellent resource. Thanks for all you do. I’m glad that the one person who knows everything about Excel charts is willing to share.
Comment from Terry
Time: Friday, November 20, 2009, 7:31 pm
Hi everyone,
Jon (or anyone else), do you have any feeling on the reason MS decided to arbitrarily disallow use of functions in those text box formulas?
In my particular case at the moment, it’s a pivotchart.
It’s not like it serves to limit the computation that a graph update can require–relative to using an intermediary cell, that is–in fact it should increase it marginally. (If that were the motive, they would’ve also prevented such an obvious work-around by preventing re-evaluation of any cell referenced by a text box in a chart.)
So if it’s not about computation involved in refreshing,… my best guess would be that it’s something about not wanting to deal with some would-be implication of having formula located anywhere but cells. (Or are there already formulas outside cells?)
Any thoughts?
Comment from Jon Peltier
Time: Friday, November 20, 2009, 11:57 pm
Terry -
I don’t think that functions were arbitrarily disallowed from text element formula links. I think these links were intended to be just that: links. Charts themselves are not responsible for many calculations, other than figuring out positions and sizes of the various chart elements. It is up to the spreadsheet designer to provide the appropriate text in the linked cell, by functions or other means.
Comment from Matt
Time: Thursday, May 13, 2010, 5:56 pm
Your article is very helpful when you want the text to go from a cell to a textbox on a chart, but what I am having a hard time figuring out (and finding info on), is how to have the text populate in a cell from the textbox on the chart. It’s probably something simple, but it just isn’t coming to me. Also, I would prefer to avoid VBA in this case if possible. (Otherwise I wouldn’t need to ask. lol)
Comment from Jon Peltier
Time: Thursday, May 13, 2010, 8:23 pm
Matt -
It doesn’t work that way. Can’t you generate the contents of a cell using a formula? This can be based on the same information that the chart text uses.
Comment from Matt
Time: Thursday, May 13, 2010, 10:04 pm
I was just thinking that it might be nice for the “user” to be able to change the “instances >” someNumber from a Textbox on the dynamic chart itself, rather than having to link a cell to the chart. I was curious to see if it could be done, considering Microsoft certainly tries to think of everything. =P
Comment from Jon Peltier
Time: Friday, May 14, 2010, 6:20 am
Matt -
You might be able to use a scrollbar to change the value in a cell, then show this value in a textbox in the chart. Of course, if the chart is embedded in a sheet, the chart is surrounded by an ocean of cells for you to use.



















Write a comment
I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.
If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.
Read the PTS Blog Comment Policy.