Adding data labels to a chart using VBA
Part one of a five-part series of blogs

Adding basic data labels to a chart can be done without using any programming code. This blog, however, shows you how to fine-tune Excel chart labels using VBA (Visual Basic for Applications) macros.

  1. The Problem With Labelling the Data Points in an Excel Scatter Chart (this blog)
  2. Setting Up the example for labelling data points in a chart
  3. Using VBA in Excel to Modify Charts
  4. Adding Data Labels to a Chart Using VBA Loops
  5. Improving the VBA system for chart data labels

Posted by Andrew Gould on 08 June 2011

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

The Problem With Labelling the Data Points in an Excel Scatter Chart

Labelling the data points in an Excel chart is a useful way to see precise data about the values of the underlying data alongside the graph itself.  In a column chart, for instance, you might show the value of the data point at the top of a column.

Example of a column chart

A useful addition to a column chart is a set of data labels showing the value of each column.

In certain types of charts, for instance scatter charts or bubble charts, the most useful way to label the data points is apparently impossible to achieve!

Data: run time against budget Data points without labels
We can plot the Run Time against the Budget... ...but we can't show the Film Titles in the chart!

The only three options you have when adding a data series to a scatter chart or bubble chart are:

  • The value of the X axis (the Run Time value in the above example).
  • The value of the Y axis (the Budget value in the above example).
  • The name of the data series (the word "Budget" in the above example).

If you choose to show all three options, the resulting chart looks something like this:

A messy chart

It's messy, difficult to read, and it's not even the information we want to see!

There are two ways to get the Film Title in the data labels:

  • Identify which data point represents which film and then manually type in the film title.  Seriously!
  • Use a bit of VBA magic to automatically label each data point with the click of a single button.

Guess which method we're going to describe in part 2 of this series?!

This blog has 0 threads Add post