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

Labeling X-Y Scatter Plots

Written by Allen Wyatt (last updated August 10, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


1

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 excellent book Excel 2003 Power Programming with VBA.)

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 (3503) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Non-adjusting References in Formulas

Sometimes making sure that a reference in a formula doesn't get changed is not as simple as putting dollar signs in front ...

Discover More

Choosing an Insert Method for Pictures

The way that you choose to add pictures to your document can have an effect on the file size of those documents. It is ...

Discover More

Automating a Manual Process with a Macro

The entire purpose of macros is to allow you to automate repetitive or tedious tasks with relative ease. How easy the ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Smoothing Out Data Series

One way you can make your charts look more understandable is by removing the "jaggies" that are inherent to line charts. ...

Discover More

Automatically Updating Charts for Additional Data

Add information to the data on which a chart is based, and you may find out that the information is excluded from the ...

Discover More

Turning the Legend On and Off

When you create a chart in Excel, the program may automatically add a legend that explains the contents of the chart. In ...

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 + 5?

2018-08-31 12:44:40

Konstantine

Thank you so much for this, I spent half a day fighting with @#$@% excel and VB to get this to work!


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.