Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Labeling X-Y Scatter Plots.

Labeling X-Y Scatter Plots

Written by Allen Wyatt (last updated June 30, 2021)
This tip applies to Excel 2007 and 2010


13

Martin has a worksheet containing 50 rows of data, each row describing a single object. Column A contains the name of the object, column B contains its X coordinate, and column C contains its Y coordinate. When he creates an X-Y scatter chart (column B against column C) the result, as desired, is a graph showing an array of points showing the location of the objects. However, Martin can't seem to label the data points with their individual names (from column A). When he tries to label the data points the only available options are to label each point with its X value, Y value, or Series Name. Martin wonders if there is a way he can easily use Column A to label the plotted data points.

This can be done manually, but it is tedious at best. For 50 rows it would quickly be brutal, so it is best to look at a macro-oriented approach. One idea is to use a macro similar to the following, which steps through the data points in the X-Y chart and reads the label values from column A.

Sub DataLabelsFromRange()
    Dim Cht As Chart
    Dim i, ptcnt As Integer

    Set Cht = ActiveSheet.ChartObjects(1).Chart
    On Error Resume Next
    Cht.SeriesCollection(1).ApplyDataLabels _
      Type:=xlDataLabelsShowValue, _
      AutoText:=True, _
      LegendKey:=False

    ptcnt = Cht.SeriesCollection(1).Points.Count
    For i = 1 To ptcnt
        Cht.SeriesCollection(1).Points(i).DataLabel.Text = _
          ActiveSheet.Cells(i + 1, 1).Value
    Next i
End Sub

The macro assumes that the first row of the worksheet contains header information and that the actual data begins in row 2. If the data really begins in row 1, then change "i + 1" to simply "i". (This macro approach is actually a variation of a macro found on pages 570-571 of John Walkenbach's book Excel 2003 Power Programming with VBA. Despite the book's title, the macro still works just fine with later versions of Excel.)

One rather unique non-macro approach is to use Excel's custom formats. All you need to do is set up a bunch of custom formats that contain only the text you want to be displayed. For example, if you have the values Age, 15, and 23 in cells A3 to C3, you can format either cell B3 or C3 to show the word "Age" even though the value will remain 15 or 23, respectively. Just enter "Age" (including the quotation marks) for the Custom format for the cell. Then format the chart to display the label for X or Y value.

When you do this, the X-axis values of the chart will probably all changed to whatever the format name is (i.e., Age). However, after formatting the X-axis to Number (with no digits after the decimal in this case) rather than General, the chart should display correctly.

This approach can obviously still take a bit of time to implement as you set up and apply a bunch of custom formats for each value in your data series. If you don't want to mess with writing and testing your own macros or creating a bunch of custom formats, you can always turn to add-ins written by others. Microsoft MVP Rob Bovey has created an excellent (free) add-in for Excel which includes an X-Y labeling feature among several others. It can be downloaded at this address:

http://www.appspro.com/Utilities/ChartLabeler.htm

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 (11652) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Labeling X-Y Scatter Plots.

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

Creating Individual Workbooks

Workbooks can contain many worksheets. If you want to pull a workbook apart and create a whole series of workbooks based ...

Discover More

Cannot Open Multiple Word Documents

What are you to do if you try to open a document and Word automatically closes your previous document? Word is not ...

Discover More

Disabling Shift Key Use when Opening a Workbook

Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Changing Elements in Lots of Charts at One Time

Got a bunch of charts that you need to make formatting changes in? You can use a macro (or two) to apply the formatting ...

Discover More

Locking Callouts to a Graph Location

If you add callouts using the drawing tools in Excel, you may have noticed that they don't always stay where you expect ...

Discover More

Embedding an Excel Chart in a Word Document

As components of the Microsoft Office suite, one would expect Excel and Word to work together. One of the most common ...

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}] (all 7 characters, in the sequence shown) 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 6 + 7?

2020-05-27 07:44:45

Amos

Thanks Allen, Its been great help.
Here is modified vision for 2 series scatter plots - for whom in need :

Sub DataLabelsFromRange()
Dim Cht As Chart
Dim i, ptcnt As Integer

Set Cht = ActiveSheet.ChartObjects(1).Chart
On Error Resume Next
Cht.SeriesCollection(1).ApplyDataLabels _
Type:=xlDataLabelsShowValue, _
AutoText:=True, _
LegendKey:=False

ptcnt = Cht.SeriesCollection(1).Points.Count
For i = 1 To ptcnt
Cht.SeriesCollection(1).Points(i).DataLabel.Text = _
ActiveSheet.Cells(i + 1, 1).Value
Next i

Set Cht = ActiveSheet.ChartObjects(2).Chart
On Error Resume Next
Cht.SeriesCollection(2).ApplyDataLabels _
Type:=xlDataLabelsShowValue, _
AutoText:=True, _
LegendKey:=False

ptcnt = Cht.SeriesCollection(2).Points.Count
For i = 1 To ptcnt
Cht.SeriesCollection(2).Points(i).DataLabel.Text = _
ActiveSheet.Cells(i + 1, 1).Value
Next i

End Sub


2018-06-06 05:47:48

Richard

Without an example in front of me, I assume that the article's macro plots data labels for all the points on the scatter chart. Could this be adapted to show selected data labels?


2016-08-15 17:45:58

Lori

Thank you! This worked like a charm.


2016-03-30 03:51:31

im

Thanks Benoit


2015-11-14 08:47:15

Benoit

There is a way to do this without a macro from excel 2013, check this out http://exde601e.blogspot.ch/2014/11/adding-labels-to-excel-scatter-charts.html


2015-10-28 14:22:08

CB

I'm trying to use this macro to apply labels to data points from multiple series within a single scatter plot (actually a bubble plot, but same idea) and have found that it only ties labels to data points from the first series. Is there any way to adapt the macro so it will apply labels to data points from all series?


2015-04-21 22:17:52

Leslie Russek

Awesome fix. Just what I needed! Tx.


2015-03-24 16:20:49

jon

@Paul Seaman - you are a genius! Your tip was by far the easiest solution. Thanks a million!


2015-02-24 13:29:39

Steve M

This works perfectly for Excel 2007, thank you!


2015-02-23 05:36:13

shetie

I am also doing the same thing but stacked at this point. Is there any one who share me microsoft excel 2013


2015-01-02 16:51:00

M.

Fantastic program! Thank you!


2014-12-31 08:02:44

Paul Seaman

I think Excel 2013 may have solved this problem.

Create the scatter chart from the data columns (cols B and C in this example).

Right click a data point on the chart and choose Format Data Labels

In the Format Data Labels panel which appears, select Label Options at the top and then the last (column chart) icon (Label Options) just below.

In the Label Contains list, tick Value from Cells and click the Select Range button to select the cells containing the labels you wish to use.


2014-09-12 10:33:16

Archana Acharya

Thank you so much for this post. It was exactly what I was looking for.Thank you for saving me a ton of grief sir!


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.