Chart Partial Range Between Variable Endpoints

Plotting Part of a Data Range

Excel is pretty handy for collecting, analyzing, and charting lots of data. If you want to plot a subset of your data, you can manually adjust the data range used by the chart. But there are easier ways to select partial data ranges, and to make this selection less tedious than manually adjusting the chart’s data.

Plotting the Entire Range

In the workbook named “MSFT Price.xlsx” (click to download) and its worksheet named “MSFT 5-week” I have a range and chart showing five weeks of Microsoft adjusted closing price data.

Chart Entire Range

The series formula of the chart is:

=SERIES('MSFT 5-week'!$B$1,'MSFT 5-week'!$A$2:$A$26,'MSFT 5-week'!$B$2:$B$26,1)

Recall that the series formula includes the chart data as follows:

=SERIES(Series Name, X Values, Y Values, Plot Order)

and that the series can be edited right in the Formula Bar, just like any other Excel formula.

A commonly asked question is, How can we plot part of this data, based on some kind of lookup? We’ll use a technique known variously as “Names” (the official moniker), “Defined Names”, “Defined Ranges”, and “Named Ranges”. I’ll show three approaches, which increase in complexity but also in ease of use.

Defined Names – By Index

This exercise is in a worksheet named “MSFT By Index”. The data is the same and the chart is nominally the same as above. We’ll use cells E2:E3 to contain the index of the first and last rows of the data range we want to plot. We will count rows in the data range and enter values into these cells.

Dynamic Names by Count

To define names, go to the Formulas tab of the ribbon, click on the Define Name button, and select Define Name… from the dropdown menu.

Define Names

The New Name dialog appears. You can name the name, define its scope to the entire workbook or to one of its worksheets, add a comment, and write a formula which the name refers to.

Define Name Dialog

For the dates in our chart, we will define the following name:

Name: MSFT_Date_Index
Refers To:
=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$2,0):
     OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$3,0)

OFFSET takes three arguments: a reference range, the number of rows down from this reference (up for a negative number of rows), and the number of columns to the right of the reference (to the left for a negative number of columns). OFFSET may take two more arguments: the number of rows high and the number of columns wide the resulting range is; if height and width are not entered, the resulting range is the same size as the reference range.

This OFFSET:

=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$2,0)

indicates the cell $E$2 rows down and zero columns right from $A$1, while this OFFSET:

=OFFSET('MSFT By Index'!$A$1,'MSFT By Index'!$E$3,0)

indicates the cell $E$2 rows down and zero columns right from $A$1. Combining the two OFFSETs, separated by a colon, indicates the range bracketed by the two cells.

For the values, we will use this simple OFFSET that returns the prices in the column immediately to the right of the dates defined by MSFT_Date_Index:

Name: MSFT_Close_Index
Refers To:
=OFFSET(MSFT_Date_Index,0,1)

To make the chart dynamic, replace the cell addresses of the X and Y values in the original series formula:

=SERIES('MSFT By Index'!$B$1,'MSFT By Index'!$A$2:$A$26,'MSFT By Index'!$B$2:$B$26,1)

with the names we’ve defined. Here is the series formula as edited in the formula bar:

=SERIES('MSFT By Index'!$B$1,'MSFT By Index'!MSFT_Date_Index,
            'MSFT By Index'!MSFT_Close_Index,1)

Since the names were scoped to the workbook, the worksheet name in the series formula is replaced by the workbook name:

=SERIES('MSFT By Index'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Index,
            'MSFT Price.xlsx'!MSFT_Close_Index,1)

Here is the chart for an arbitrary pair of first and last index values:

Dynamic Names by Count

Adjust the first and last indices in E2:E3, and the chart updates to reflect the new range.

Dynamic Names by Count

This is a bit tedious in practice, since you need to count rows and enter your findings in the index cells. It is not hard to make the process easier.

Defined Names – By Match

This exercise is in a worksheet named “MSFT By Match”. The data and the chart are the same as above. We’ll use cells F2:F3 to contain the first and last dates of the data range we want to plot. Formulas in E2:E3 will determine the index of these dates within the date range, so we can use the same formulas as above for our names. We will enter dates into cells F2:F3 and let Excel calculate the index values in E2:E3, which is a little nicer than counting rows and typing a number.

Dynamic Names by Match
These formulas in E2:E3 determine the where the dates in F2:F3 fall in the overall list of dates:

Cell E2:  =MATCH(F2,$A$2:$A$26,-1)
Cell E3:  =MATCH(F3,$A$2:$A$26,-1)

The last argument (-1) in the functions is needed because the dates in column A are listed in descending order. Omit this argument, or use +1, for data sorted in ascending order. Use zero if the data are unsorted labels.

The name that includes the dates for our chart is:

Name: MSFT_Date_Match
Refers To:
=OFFSET('MSFT By Match'!$A$1,'MSFT By Match'!$E$2,0):
     OFFSET('MSFT By Match'!$A$1,'MSFT By Match'!$E$3,0)

This is the same, except for the sheet name, as in the previous exercise. The corresponding name for the prices should also look familiar:

Name: MSFT_Close_Match
Refers To:
=OFFSET(MSFT_Date_Match,0,1)

The series formula for the dynamic chart looks like this as edited:

=SERIES('MSFT By Match'!$B$1,'MSFT By Match'!MSFT_Date_Match,
            'MSFT By Match'!MSFT_Close_Match,1)

and like this when Excel replaces the sheet name with the workbook name for the workbook-scoped names:

=SERIES('MSFT By Match'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Match,
            'MSFT Price.xlsx'!MSFT_Close_Match,1)

Here is how the chart looks for an arbitrary pair of dates:

Dynamic Names by Match

Adjust the first and last dates in F2:F3, and the chart updates to reflect the new range.

Dynamic Names by Match

It’s much easier to enter dates than to count rows, especially if the overall data range extended beyond the number of rows visible in one screen.

Defined Names – By Combo Box

This exercise is in a worksheet named “MSFT By Combo”. The data and the chart are the same as above. We’ll use combo box controls that let us select the first and last dates of the data range we want to plot. The combo boxes link to cells E2:E3, so we can again use the same formulas as above for our names. Now we’ll use the best method in this article: we’ll select the dates we want using the combo boxes.

Dynamic Names by Match

To add a combo box control, go to the Developer tab, click Insert, then click the Combo Box from the set of Forms Controls. The cursor turns into a shape crosshair; use this to draw the combo box.

Dynamic Names by Combo

If the Developer tab is not visible, you have to change your settings. In Excel 2010 and 2013, click the green File tab, select Options, select Customize Ribbon, and in the long list of tabs on the right, check the box in front of Developer. In Excel 2007, click the big round Office button in the top left of the Excel window, click Excel Options at the bottom of the dialog, then check Show Developer Tab in the Ribbon.

Right click on the combo box, and choose Format Control from the pop-up. Select the input range (the range of dates that you want to appear in the dropdown) and the cell link (where the index of the selected date will appear).

Dynamic Names by Combo
With both combo boxes formatted, defining the names proceeds as above, with essentially the same formulas. The dates:

Name: MSFT_Date_Combo

Refers To:
=OFFSET('MSFT By Combo'!$A$1,'MSFT By Combo'!$E$2,0):
     OFFSET('MSFT By Combo'!$A$1,'MSFT By Combo'!$E$3,0)

The price values:

Name: MSFT_Close_Combo
Refers To:
=OFFSET(MSFT_Date_Combo,0,1)

Here is the series formula as edited to reflect the names:

=SERIES('MSFT By Combo'!$B$1,'MSFT By Combo'!MSFT_Date_Combo,
            'MSFT By Combo'!MSFT_Close_Combo,1)

and adjusted by Excel to show the workbook name for the workbook-scoped names:

=SERIES('MSFT By Combo'!$B$1,'MSFT Price.xlsx'!MSFT_Date_Combo,
            'MSFT Price.xlsx'!MSFT_Close_Combo,1)

Dynamic Names by Combo

Adjust the first and last dates selected in the combo boxes, and the chart updates to reflect the new range.

Dynamic Names by Combo

Peltier Tech Chart Utility

Polar Plot in Excel

Polar Plots

Microsoft Excel offers a number of circular charts, but none of them is usually a particularly good choice for displaying data. You can search this blog for “pie chart” and see numerous examples of badly applied pie charts. If you hunt for “radar chart” or “spider chart” you’ll see a class of charts that’s even more deceptive. A major part of the deficiency of radar plots is that they pretend to show a physical, geographical relationship which isn’t present at all.

Excel Polar Plot

Polar Plots, on the other hand, can be used to map information that has a true geographical component. Ironically, this includes actual radar feedback. The data for a polar plot is given in polar coordinates, which is given as R-theta, where R is the distance from the origin (center of the plot) and theta is the angle from a reference angle, such as north or conversely the positive horizontal axis of overlaid cartesian coordinates.

A Polar Plot is not a native Excel chart type, but it can be built using a relatively simple combination of Donut and XY Scatter chart types. We need to build the grid using a donut chart, then overlay the physical data using applicable XY Scatter chart types.

Preparing the Data

We’ll use a donut chart for the circular grid. The data we need is simple, as shown below. I have 9 columns for the 9 concentric donuts (the smallest donut hole is 10% of the diameter, so this hole plus 9 rings of 10% make 100%). Each ring has 12 segments, so each comprises 30° of the 360° circle of the chart.

Excel Polar Plot Grid Data

Our data is provided in polar coordinates in columns A and B below, where R is the distance from the origin to the data point, and theta is the angle from our reference angle (due north) to the point. These are converted to X and Y in columns C and D. The formula in C2and D2 are:

C2:  =A2*SIN(B2/180*PI())
D2:  =A2*COS(B2/180*PI())

These are filled down to C14 and D14.

Excel Polar Plot Values Data

Making the Chart

To create the grid, select the blue shaded cells in the top table, and insert a donut chart (below left). The default diameter of the donut hole is 75% of the diameter of the whole chart, so all of the rings are scrunched together. Select any of the donuts and press Ctrl+1 (numeral one) to open the Format Series dialog or task pane, and set Donut Hole Size to 10%, the smallest possible value (below right). While you’re at it, shrink the ridiculously large chart title, if you need it at all.

Excel Polar Plot Steps 1 and 2

Format each donut series so it has no fill and uses a thin (0.75 point) light gray (25% gray) border (below left). Our grid is ready for real data.

Select the orange shaded range of XY values in the second table above, and copy. Select the chart, and click the Paste Special button on the Paste dropdown on the Home tab of the ribbon to add the data (below right). The data is added as another concentric donut on the outside of the chart.

Excel Polar Plot Steps 3 and 4

Use the following settings in the Paste Special dialog: Add cells as New Series, Values in Columns, Series Names in First Row, and Categories in First Column.

Paste Special Chart Dialog
Select the added ring of data, and choose Change Series Chart Type from the pop-up menu. Choose one of the XY types. Here I’ve selected the line and markers option (below left); if you were plotting the advance of alien spacecraft you’d probably want the markers only option.

Excel has plotted the XY data on secondary axes: the axis labels of both are plainly visible in the left chart below. Format each secondary axis scale in turn so the minimum and maximum are equal but with opposite signs; in this case min is -10 and max is +10. Format the axis so there are no tick marks and no tick labels, and use the same line style as the donut grid borders, 0.75 points thick and 25% gray (below right).

Excel Polar Plot Steps 5 and 6

Remove the major vertical and horizontal gridlines (below left). Remove the unwanted legend entries; click once to select the legend, then once more to select the unwanted entry, then click Delete (below right). If there is only one series of XY points, you can probably dispense with the legend.

Excel Polar Plot Steps 7 and 8

Expand the size of the plot area (below left), and format the series lines and markers if desired (bottom right).

Excel Polar Plot Steps 9 and 10

This may be complete enough for you, but as always, there are embellishments available to the clever chartmonger.

Modified Grid

You can change the grid if you like. If I use the following expanded data, the inner few donuts have only 4 arcs, each covering 90° of the ring. The next few have 12 arcs, as above, each covering 30°. The last few have 24 arcs, covering 15° each.

Excel Polar Plot Extended Grid Data

The resulting grid is shown without data below left, and with data below right.

Excel Polar Plot Fancy Grid

You can show the central circle (donut hole) without the crosshairs if you format the secondary axes to use no line color instead of 25% gray.

Excel Polar Plot Fancy Grid Without Crosshairs

Compass Point Labels

Suppose this is an actual geographic representation and you want to label the points of the compass. Set up data as shown below left. Copy the green range, select the chart, and use Paste Special as above. This series is plotted using the same chart type as the previous paste series was converted to, XY scatter with lines and markers.

Excel Polar Plot with Labels Data and Step 1

Add labels to the new series; the default Y values are used in the labels (below left). Remove the title and legend, or shrink the plot area to make room for the labels.

Change the label positions to Above (for the north label), Right (east), Below (south), and Left (west).

Excel Polar Plot Steps 2 and 3

Change the labels as appropriate (below left). You can use one of these approaches:

  • Select each label (click to select the series of labels, then click again to select the individual label), double click to edit the label’s text, and type the label you want.
  • Select each label (click to select the series of labels, then click again to select the individual label), type an equals sign in the formula bar, and click on the cell containing the label you want. The formula bar will show the link, e.g., =WorksheetName!$F$2.
  • Download and install Rob Bovey’s free Chart Labeler from http://appspro.com. This allows you to assign labels from a worksheet range to the points in a chart.
  • If you’re using Excel 2013, you can format the labels to use Values from Cells, and select the range of cells containing your labels.

Finally, format the last data series so it uses no lines and no markers (below right).

Excel Polar Plot Steps 4 and 5

Peltier Tech Chart Utility

Chart Events in Microsoft Excel

Chart Events

When you use a computer, you continuously interact with objects and programs, through events. An event is anything that happens, such as moving the mouse, clicking on objects, changing data, or activating windows. Programs can raise events of their own as well. A program can respond to events using event procedures. For example, if you click a scroll button, Excel responds by scrolling the window down.

As a programmer, you can write event procedures that will respond to (or trap) events by users. These event procedures can trap events in the worksheet, in the workbook, at the application level, or in a chart. In this article, I introduce you to chart event procedures in Microsoft Excel, which you can use for charts on a chart sheet and embedded charts.

Why Use Chart Events?

Chart events can make it much easier for people to use your programs, and add interactivity to your charts. Perhaps you need users to select a point in a series. If you create an event procedure that detects a click on the chart, users won’t have to type in a series name and a point number.

After the click the program can perform one or more useful tasks:

  • Display a customized chart tip;
  • Extract information from the chart and place it in a worksheet;
  • Activate another chart or worksheet;
  • Identify points to be included in a subsequent analysis.

Although Excel can accept data in a variety of formats and arrangements, you can do certain things with the data to ensure your charts are easy to build and maintain. “Good data” has these characteristics:

  1. Data for each series is arranged in Columns (preferable to Rows)
  2. First column is used for Categories (X axis labels)
  3. First row is used for Series Names
  4. Top left cell is blank
  5. Data below series names is numeric (right-adjusted with no alignment specified)
  6. There are no blank rows or blank columns within the data range
  7. There is a buffer row or column between the table and any other non-blank cells.

Well-Formed Chart Data

In this case, I use sample data similar to the above above to demonstrate chart event procedures.

Chart Sheet Events

The first set of examples is for charts that reside on their own sheets, not embedded in worksheets. These examples are contained in the downloadable workbook ChartSheetEvents.xlsm.

Create A Chart Sheet

Select the entire range you want included in your chart, or select a single cell within this range. If you followed guidelines 6 and 7 about Good Data, Excel selects the range of continuous data that includes the selected cell.

Select the data range, or a single cell within the data range. Press the F11 function key, to quickly create a chart sheet from the data range range, using the default chart type.

Chart Sheet

The Chart Code Module

Right-click the chart sheet tab, and select View Code from the pop-up menu. This opens the Visual Basic Editor (VBE).

Chart Sheet Tab Context Menu

Within the VBE, a code module appears with the caption ChartSheetEvents.xlsm – Chart1 (code):

Chart Code Module

This is a special kind of code module, which is associated with the chart. Code contained in this module runs when events occur on the chart.

The code module should contain only the line

Option Explicit

This line means any variable used in the module must be explicitly declared prior to use. This approach is slightly more work, but it assures that no errant variable will be accidentally defined by a typographical error.

If the module does not include the Option Explicit line, type it in, then go to the VBE’s Tools menu, select Options…, and on the Editor tab, check the Require Variable Declarations box. Every module you create after setting this option will automatically contain the Option Explicit line.

While you’re in the dialog, you may as well uncheck Auto Syntax Check, which pops up a dialog whenever you enter code with a syntax error. Since the code with an error is also colored red, there’s no need for an annoying dialog which you have to cancel to continue.

Chart Code Module with Event Procedure Stub

Chart Event Procedure

At the top of the code module, you see two dropdowns. One contains the items (General) and Chart, the other contains (Declarations). While you can type your entire event procedure from scratch, it’s easier to use these dropdowns when creating procedures.

Select Chart from the left hand dropdown. The following stub of an event procedure appears in the code module:

Chart Code Module with Event Procedure Stub

Private Sub Chart_Activate()
 
End Sub

This procedure runs whenever the chart is activated. Between these lines, type whatever code you want to be executed when the chart is activated. For example:

Private Sub Chart_Activate()
    MsgBox "Welcome to my Chart!"
End Sub

Now when you activate the chart, the following message box appears:

Welcome Message Box

This example is demonstrated using the chart named Welcome in the companion workbook. This is just an example. Remove the message box code before it makes you insane.

More Chart Events

Chart_Activate is good for illustration of chart events, but other events can be much more useful. The chart events available to you are listed below. These can be accessed from the right hand dropdown in the chart code module when Chart is selected in the left hand dropdown.

  • Activate
  • BeforeDoubleClick
  • BeforeRightClick
  • Calculate
  • Deactivate
  • DragOver
  • DragPlot
  • MouseDown
  • MouseMove
  • MouseUp
  • Resize
  • Select
  • SeriesChange

Next you can use an event to tell which chart element has been selected. Choose Chart from the left hand dropdown of the code module, then choose Select from the right hand dropdown, to produce the following procedure stub:

Chart Code Module with Event Procedure Stub

Private Sub Chart_Select(ByVal ElementID As Long, _
        ByVal Arg1 As Long, ByVal Arg2 As Long)
 
End Sub

Note that I’ve inserted the line continuation character (an underscore) in the first line to wrap the line at a convenient place.

The Chart_Select event fires whenever a chart element has been selected. Three arguments are passed to the procedure: ElementID, which identifies the selected chart element, and Arg1 and Arg2, which provide additional information. For example, if ElementID identifies that a series has been selected, Arg1 identifies which series has been selected, and Arg2 identifies the point within the series which has been selected, or Arg1 = -1 to indicate that the entire series is selected. If Arg1 or Arg2 are not relevant to the selected ElementID, they are assigned the value zero.

When you select Chart from the left hand dropdown, the Chart_Activate procedure shell is created in the code module (Activate is the default event for a chart). You can ignore it, delete it, or use it for another purpose.

This table lists the ElementID values, and the meanings of their associated Arg1 and Arg2 parameters.

Chart Element List

No need to memorize the details, since the VBE Object Browser (VBE View menu > Object Browser) knows everything.

Object Browser showing Chart Element List

Now you can add a line to the procedure to identify which chart element has been selected, and show the values of its associated arguments:

Private Sub Chart_Select(ByVal ElementID As Long, _
        ByVal Arg1 As Long, ByVal Arg2 As Long)
 
    MsgBox "Element: " & ElementID & vbCrLf & "  Arg 1: " & Arg1 _
        & vbCrLf & "  Arg 2: " & Arg2
 
End Sub

To test your event procedure, select the chart’s title. Click OK in the message box, and then test your event procedure with other elements, such as a series, and a point in a series.

The following three message boxes appear when selecting the Chart Title (ElementID = 4), Series 1 (ElementID = 3, Arg1 = 1, and Arg2 = -1), and Series 1 Point 4 (ElementID = 3, Arg1 = 1, Arg2 = 4). To select an individual point, you must single click twice: once to select the entire series, then again to select the point.

Object Browser showing Chart Element List

This example is demonstrated using the chart named Select in the companion workbook.

These message boxes aren’t very informative – text descriptions would be more useful. Replace the Chart_Select event code with the following more extensive procedure. It converts the values to text, and creates a more informative message:

Private Sub Chart_Select(ByVal ElementID As Long, _
        ByVal Arg1 As Long, ByVal Arg2 As Long)
 
    Dim sElement As String
    Dim sArg As String
 
    Select Case ElementID
        Case xlChartArea
            sElement = "Chart Area"
        Case xlChartTitle
            sElement = "Chart Title"
        Case xlPlotArea
            sElement = "Plot Area"
        Case xlLegend
            sElement = "Legend"
        Case xlFloor
            sElement = "Floor"
        Case xlWalls
            sElement = "Walls"
        Case xlCorners
            sElement = "Corners"
        Case xlDataTable
            sElement = "Data Table"
        Case xlSeries
            sElement = "Series " & Arg1
            If Arg2 > 0 Then sArg = "Point " & Arg2
        Case xlDataLabel
            sElement = "Data Label"
            sArg = "Series " & Arg1
            If Arg2 > 0 Then sArg = sArg & ", Point " & Arg2
        Case xlTrendline
            sElement = "Trendline"
            sArg = "Series " & Arg1 & ", Trendline " & Arg2
        Case xlErrorBars
            sElement = "Error Bars"
            sArg = "Series " & Arg1
        Case xlXErrorBars
            sElement = "X Error Bars"
            sArg = "Series " & Arg1
        Case xlYErrorBars
            sElement = "Y Error Bars"
            sArg = "Series " & Arg1
        Case xlLegendEntry
            sElement = "Legend Entry"
            sArg = "Series " & Arg1
        Case xlLegendKey
            sElement = "Legend Key"
            sArg = "Series " & Arg1
        Case xlAxis
            sElement = IIf(Arg1 = 1, "Primary ", "Secondary ")
            sElement = sElement & IIf(Arg2 = 1, "Category ", "Value ")
            sElement = sElement & "Axis"
        Case xlMajorGridlines
            sElement = IIf(Arg1 = 1, "Primary ", "Secondary ")
            sElement = sElement & IIf(Arg2 = 1, "Category ", "Value ")
            sElement = sElement & "Major Gridlines"
        Case xlMinorGridlines
            sElement = IIf(Arg1 = 1, "Primary ", "Secondary ")
            sElement = sElement & IIf(Arg2 = 1, "Category ", "Value ")
            sElement = sElement & "Minor Gridlines"
        Case xlAxisTitle
            sElement = IIf(Arg1 = 1, "Primary ", "Secondary ")
            sElement = sElement & IIf(Arg2 = 1, "Category ", "Value ")
            sElement = sElement & "Axis Title"
        Case xlDisplayUnitLabel
            sElement = IIf(Arg1 = 1, "Primary ", "Secondary ")
            sElement = sElement & IIf(Arg2 = 1, "Category ", "Value ")
            sElement = sElement & "Axis Display Unit Label"
        Case xlUpBars
            sElement = "Up Bars"
            sArg = "Group Index " & Arg1
        Case xlDownBars
            sElement = "Down Bars"
            sArg = "Group Index " & Arg1
        Case xlSeriesLines
            sElement = "Series Lines"
            sArg = "Group Index " & Arg1
        Case xlHiLoLines
            sElement = "High-Low Lines"
            sArg = "Group Index " & Arg1
        Case xlDropLines
            sElement = "Drop Lines"
            sArg = "Group Index " & Arg1
        Case xlRadarAxisLabels
            sElement = "Radar Axis Labels"
            sArg = "Group Index " & Arg1
        Case xlShape
            sElement = "Shape"
            sArg = "Shape Number " & Arg1
        Case xlNothing
            sElement = "Nothing"
    End Select
 
    MsgBox sElement & IIf(Len(sArg) > 0, vbCrLf & sArg, "")
End Sub

Test your new code, by selecting elements in the chart. Here are the revised message boxes, made more informative by analyzing the ElementID and other arguments:

Object Browser showing Chart Element List

This example is demonstrated using the chart named Nicely Select in the companion workbook.

This is a more useful procedure, because it tells us in human words what has been selected. On the other hand, it is less useful than it could be, because it pops up a message box every time a new chart element is selected, forcing the user to clear the message box before proceeding.

Identify the Point Clicked By the User

Another useful event procedure tells you which point was clicked on, and display its values. Chart_Select is not the best event to trap to detect clicking on a point, because two Chart_Select events must occur when a point is selected: the series is selected by the first click, and the point by the second. The MouseUp event is a better event to trap.

To create a new event procedure, choose Chart in the left dropdown and MouseUp in the right, to create this shell:

Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
        ByVal x As Long, ByVal y As Long)
 
End Sub

Four arguments are passed to this procedure.

Button tells which mouse button was released: xlNoButton, xlPrimaryButton (usually the left button), xlSecondaryButton (right button), or xlMiddleButton.

Shift tells which keys are depressed when the mouse button was released. The value of Shift can be one or a sum of several of the following values:

Shift Key Codes

For example, if Shift = 2, the CTRL key was depressed when the mouse button was clicked; if Shift = 5, both the SHIFT and ALT keys were depressed.

The coordinates of the cursor, x and y, are in chart object client coordinate units. It’s not necessary to be concerned about these, since you just pass them along to other functions to get more useful information.

Test the following event procedure, which uses Chart_MouseUp to determine where the mouse click occurred. The procedure:

  • traps the release of the button,
  • determines where on the chart the click occurred (x, y),
  • passes these coordinates to the GetChartElement function to determine what chart element is located at these coordinates,
  • determines whether a data point (or data label) is located at the mouse click,
  • extracts the X and Y values for the data point, if the click occurred at a data point or data label,
  • displays this information in a message box.
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
        ByVal x As Long, ByVal y As Long)
 
    Dim ElementID As Long, Arg1 As Long, Arg2 As Long
    Dim myX As Variant, myY As Double
 
    With ActiveChart
        ' Pass x & y, return ElementID and Args
        .GetChartElement x, y, ElementID, Arg1, Arg2
 
        ' Did we click over a point or data label?
        If ElementID = xlSeries Or ElementID = xlDataLabel Then
            If Arg2 > 0 Then
                ' Extract x value from array of x values
                myX = WorksheetFunction.Index _
                    (.SeriesCollection(Arg1).XValues, Arg2)
                ' Extract y value from array of y values
                myY = WorksheetFunction.Index _
                    (.SeriesCollection(Arg1).Values, Arg2)
 
                ' Display message box with point information
                MsgBox "Series " & Arg1 & vbCrLf _
                    & """" & .SeriesCollection(Arg1).Name & """" & vbCrLf _
                    & "Point " & Arg2 & vbCrLf _
                    & "X = " & myX & vbCrLf _
                    & "Y = " & myY
            End If
        End If
    End With
End Sub

Here is an informative dialog that results from clicking on the 4th point of the first series. Compare to the third dialog from the last example above.

Mouse Up Dialog

This example is demonstrated using the chart named Identify Point in the companion workbook.

You could do many things with the data from this procedure.

  • A message box requires a user response to continue; you could replace the dialog by drawing a textbox with the same information, as a smarter chart tip. Use the MouseMove event instead, to mimic Excel’s normal chart tip behavior.
  • You could place this data into a worksheet range. After clicking on several points, you would have a small table of values from the selected points. These could be used for subsequent analysis.
  • You could identify the clicked point, then jump to another appropriate chart. This approach has the effect of drilling down deeper into the data. See the short example below.

Drill Down to a Related Chart

Suppose the values for the categories A through E in the chart reflected sums of other values. You could have several other chart sheets, Chart A through Chart E, that show detail for the selected categories. An event procedure such as the following produces this kind of drill down effect (to test the procedure, create chart sheets named Chart A, Chart B, etc.):

Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
        ByVal x As Long, ByVal y As Long)
 
    Dim ElementID As Long, Arg1 As Long, Arg2 As Long
    Dim myX As Variant
 
    With ActiveChart
        ' Pass x & y, return ElementID and Args
        .GetChartElement x, y, ElementID, Arg1, Arg2
 
        ' Did we click over a point or data label?
        If ElementID = xlSeries Or ElementID = xlDataLabel Then
            If Arg2 > 0 Then
                ' Extract x value from array of x values
                myX = WorksheetFunction.Index _
                    (.SeriesCollection(Arg1).XValues, Arg2)
 
                ' Don't crash if chart doesn't exist
                On Error Resume Next
                ' Activate the appropriate chart
                ThisWorkbook.Charts("Chart " & myX).Select
                On Error GoTo 0
            End If
        End If
    End With
End Sub

To return to the starting chart on another mouse click, you can add the following Chart_MouseUp event procedure to the code modules of the detail charts. For example, add the following procedure to the code module for the Chart A sheet. When you select an element in Chart A, you’ll return to the main chart:

Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)

    ' Don't crash if chart doesn't exist
    On Error Resume Next
    ' Return to calling chart
    ThisWorkbook.Charts("Chart Drilldown").Select
    On Error GoTo 0

End Sub

This example is demonstrated using the charts named DrillDown and Chart A through Chart E in the companion workbook.

The VBE Project Explorer

You may have noticed the Project Explorer window of the Visual Basic Editor. By default it is docked in the upper left of the VB window. If the Project Explorer window is not open, from within the VBE, choose VBE View menu > Project Explorer or press Ctrl+R. Here is the Project Explorer window in its floating (undocked) state.

VBE Project Explorer Pane

Every VBA Project that you have open in Excel is listed in the Project Explorer, including open workbooks and installed add-ins. If the project is unprotected, its constituent objects are listed in a tree view structure underneath it. If the folder icon in the toolbar is selected, the objects are grouped. If the folder icon is not selected, the objects are listed in alphabetical order without grouping.

You can see three of the four groups of objects in the screenshot above. All chart sheets and worksheets are listed under the Microsoft Excel Objects group, with the ThisWorkbook object that represents the workbook itself. Regular code modules are listed under the Modules group, where we see the module named MChartEvents in the workbook ChartClassEvents.xlsm. The Class Modules group contains class modules, such as CAppEvent and CChartEvent, which will be constructed later in this article. If a project has any user forms, these will be listed under the Forms group.

Under Microsoft Excel Objects, the sheets and workbook are listed in alphabetical order by their “Code Name”. The Code Name is the name of the object in the VB Editor; we see code names Chart1 through Chart5, Chart5a through Chart5e, Sheet1, and ThisWorkbook are shown above. The Excel name of an object is shown in parentheses after its Code Name. You can change the Code Name by changing the (Name) property in the VBE’s Properties window; if you change the Name property, the name displayed on the sheet tab in Excel will be changed.

To access a sheet’s code module, double click it in the Project Explorer window, or right-click a sheet tab in Excel and choose View Code. To access the workbook’s code module, double-click on the ThisWorkbook object in the Project Explorer window.

New Forms, Modules, and Class Modules are added to a project using the VBE’s Insert menu. A new chart sheet or worksheet object is added whenever a sheet is created within Excel. A new project is added to the Project Explorer’s list when a workbook is created or opened, or an add-in is installed, within Excel.

Embedded Chart Events

The approach I have described so far is effective, but only for a single chart sheet. To apply to multiple chart sheets, the event code has to be copied to each chart sheet’s code module. It does not work at all for embedded charts.

A more flexible and powerful technique is to use a class module to trap chart events. A class module can be used for any chart, whether it’s an embedded chart or chart sheet. And it eliminates the need to place the code in a chart sheet’s code module. Any events in the code module of a chart are available in a chart event class module. A chart event class module is demonstrated in the downloadable workbook ChartClassEvents.xlsm.

To create a new class module, click Alt+F11 to switch to the VB Editor. Make sure the ChartClassEvents.xlsm workbook is selected in the Project Explorer window.

Within the VBE, choose Insert menu > Class Module. A new code module opens, with the caption ChartClassEvents.xlsm – Class1 (Code). If the Properties window is not open, choose View menu > Properties, or press the F4 function key. In the Properties window, change the class name to CChartEvent, following the convention that the name of a class module begins with capital C.

The class module should begin with this line:

Option Explicit

If not, follow the instructions in The Chart Code Module subsection in the Chart Sheet Events section of this article, above.

Next, add this line in the Declarations section of the class module, to declare a Chart type object with event trapping enabled.

Public WithEvents EventChart As Chart

After adding this line, the class module contains the EventChart item in the left hand dropdown, in addition to (General) and Class. When the EventChart item is selected, all of the chart events described in the first half of this article appear in the right hand dropdown.

To create the equivalent chart event procedure as you created in the “More Chart Events” subsection above, select EventChart from the left dropdown and Select from the right dropdown, to produce this procedure shell:

Private Sub EventChart_Select(ByVal ElementID As Long, _
        ByVal Arg1 As Long, ByVal Arg2 As Long)
 
End Sub

The shell of the EventChart_Activate procedure is produced when the EventChart item is selected in the left dropdown. This can be deleted or ignored. Add the Msgbox command within this procedure to identify the element and arguments for the selected chart element. The entire class module code should look like this:

Option Explicit
 
' Declare object of type "Chart" with events
Public WithEvents EventChart As Chart
 
Private Sub EventChart_Select(ByVal ElementID As Long, _
        ByVal Arg1 As Long, ByVal Arg2 As Long)
 
    MsgBox "Element: " & ElementID & vbCrLf & "  Arg 1: " & Arg1 _
        & vbCrLf & "  Arg 2: " & Arg2
 
End Sub

The code is almost ready to trap chart events, but first you need to enable events for the chart.

Enabling Events for the Chart

Make sure the ChartClassEvents.xls workbook is selected in the Project Explorer window. From the VBE Insert menu, select Module. A new code module opens, with the caption ChartClassEvents.xls – Module1 (Code). In the Properties window, change the module name to MChartEvents, following the convention that the name of a regular module begins with capital M.

The module should begin with this line:

Option Explicit

If not, follow the instructions in “The Chart Code Module” section. Now you must declare an instance of the chart events class, by adding this line in the Declarations section of the class module, immediately below the Option Explicit line.

Dim clsChartEvent As New CChartEvent

Next, you create two procedures, Set_This_Chart and Reset_Chart, To activate a chart for events, you assign the active chart to the EventChart property of the instance of the class:

Set clsChartEvent.EventChart = ActiveChart

To deactivate the chart for events, you assign the EventChart property of the instance of the class to Nothing:

Set clsChartEvent.EventChart = Nothing

These two lines are wrapped in the Set_This_Chart and Reset_Chart procedures, with a check within the Set_This_Chart procedure to prevent errors if no chart is selected. The entire module looks like this:

Option Explicit
 
Dim clsChartEvent As New CChartEvent
 
Sub Set_This_Chart()
    ' Skip if no chart is selected to prevent an error
    If Not ActiveChart Is Nothing Then
        ' Enable events for the active chart
        ' Works for chart sheets and embedded charts
        Set clsChartEvent.EventChart = ActiveChart
    End If
End Sub
 
Sub Reset_Chart()
    ' Disable events for chart previously enabled as active chart
    Set clsChartEvent.EventChart = Nothing
End Sub

To test the procedures, select any chart, embedded or chart sheet, and run Set_This_Chart. Now select any chart element, and a message box pops up to tell you the ElementID, Arg1, and Arg2.

Enabling Events for Chart(s)

This approach is fine for a single embedded chart, but it can be broadened to include all charts embedded in the active sheet. Instead of a variable clsChartEvent, you declare an array clsChartEvents() to contain all of the enabled charts, and wrap them within loops so all embedded charts on the active sheet are included.

Adjust the MChartEvents module to look like this:

Option Explicit
 
Dim clsChartEvents() As New CChartEvent
 
Sub Set_All_Charts()
    ' Enable events for all charts embedded on a sheet
    ' Works for embedded charts on a worksheet or chart sheet
    If ActiveSheet.ChartObjects.Count > 0 Then
        ReDim clsChartEvents(1 To ActiveSheet.ChartObjects.Count)
        Dim chtObj As ChartObject
        Dim chtnum As Integer
 
        chtnum = 1
        For Each chtObj In ActiveSheet.ChartObjects
            ' Debug.Print chtObj.Name, chtObj.Parent.Name
            Set clsChartEvents(chtnum).EventChart = chtObj.Chart
            chtnum = chtnum + 1
        Next ' chtObj
    End If
End Sub
 
Sub Reset_All_Charts()
    ' Disable events for all charts previously enabled together
    Dim chtnum As Integer
    On Error Resume Next
    Set clsChartEvent.EventChart = Nothing
    For chtnum = 1 To UBound(clsChartEvents)
        Set clsChartEvents(chtnum).EventChart = Nothing
    Next ' chtnum
End Sub

Activate a sheet with embedded charts and run Set_All_Charts. All embedded charts will now respond to chart events as the single embedded chart did in the previous section. This approach works for any embedded charts on a worksheet or a chart sheet (yes, you can embed chart objects on a chart sheet).

The previous code won’t activate the parent chart sheet, however. You reinstate the clsChartEvent declaration, to be used with the chart sheet, and adjust the Set_All_Charts procedure to activate a chart sheet and then activate the embedded charts.

Modify the module to look like this:

Option Explicit
 
Dim clsChartEvent As New CChartEvent
Dim clsChartEvents() As New CChartEvent
 
Sub Set_All_Charts()
    ' Enable events for active sheet if sheet is a chart sheet
    If TypeName(ActiveSheet) = "Chart" Then
        Set clsChartEvent.EventChart = ActiveSheet
    End If
 
    ' Enable events for all charts embedded on a sheet
    ' Works for embedded charts on a worksheet or chart sheet
    If ActiveSheet.ChartObjects.Count > 0 Then
        ReDim clsChartEvents(1 To ActiveSheet.ChartObjects.Count)
        Dim chtObj As ChartObject
        Dim chtnum As Integer
 
        chtnum = 1
        For Each chtObj In ActiveSheet.ChartObjects
            ' Debug.Print chtObj.Name, chtObj.Parent.Name
            Set clsChartEvents(chtnum).EventChart = chtObj.Chart
            chtnum = chtnum + 1
        Next ' chtObj
    End If
End Sub
 
Sub Reset_All_Charts()
    ' Disable events for all charts previously enabled together
    Dim chtnum As Integer
    On Error Resume Next
    Set clsChartEvent.EventChart = Nothing
    For chtnum = 1 To UBound(clsChartEvents)
        Set clsChartEvents(chtnum).EventChart = Nothing
    Next ' chtnum
End Sub

Using Event Procedures to Enable Chart Events

Event procedures in Microsoft Excel have different levels of influence. In the earlier example, the event procedures in the code module behind a chart sheet only detect events within the chart sheet. Similarly, event procedures on a worksheet’s code module only detect events in that worksheet. Event procedures on a workbook’s code module trap events that occur in all sheets within the workbook. Finally, application-level event procedures watch over all sheets and workbooks in Excel. There is no application code module, however, so you need to create a special class module to handle application events.

Using these events is a more convenient way to activate chart events than running the Set_All_Charts and Reset_All_Charts procedures used above. The following code examples demonstrate how you can use events to set different levels of activation for chart events:

  1. all charts in one worksheet
  2. all charts in one chart sheet
  3. all charts on all sheets in one workbook
  4. all charts on all sheets in all workbooks

You can decide which level of activation you need, based on the purpose of your chart event code. If you are only concerned with a single chart in one worksheet, you can stop with the first example. If you have built an extensive add-in that processes events for any charts, you need a full-blown application events class module. The companion workbook ChartClassEvents.xlsm follows level 4.

1. Worksheet Events to Enable All Charts In One Worksheet

You must trap the Activate and Deactivate events for the desired worksheet, and use these events to run the Set_All_Charts and Reset_All_Charts procedures. Right-click the sheet tab, and choose View Code from the pop up menu to open the VBE. You see a new code module with the caption ChartClassEvents.xls – Sheet1 (Code), assuming this is Sheet1. Choose Worksheet on the left hand dropdown and Activate from the right hand dropdown. Now type the line Set_All_Charts inside the Worksheet_Activate procedure stub. Then choose Deactivate from the right hand dropdown, and type the line Reset_All_Charts inside the Worksheet_Deactivate procedure stub. You see the following in the code module:

Option Explicit
 
Private Sub Worksheet_Activate()
    Set_All_Charts
End Sub
 
Private Sub Worksheet_Deactivate()
    Reset_All_Charts
End Sub

This code turns on chart events for all charts embedded in the worksheet when it is activated, then turns off chart events when the worksheet is deactivated. If your program executes additional code in the Worksheet_Activate and _Deactivate events, include the lines above with the other code, in the order that works best for your application.

2. Chart Sheet Events to Enable All Charts In One Chart Sheet

You need to trap the Activate and Deactivate events for the desired chart sheet, and use these events to run the Set_All_Charts and Reset_All_Charts procedures. To open the VBE, right-click the sheet tab, and choose View Code from the pop up menu. It opens the code module with the caption ChartClassEvents.xls – Chart1 (Code), assuming this is Chart1. Choose Chart on the left dropdown and Activate from the right dropdown, and type the line Set_All_Charts inside the Chart_Activate procedure shell. Then choose Deactivate from the right dropdown, and type the line Reset_All_Charts inside the Chart_Deactivate procedure shell. You see the following in the code module:

Option Explicit
 
Private Sub Chart_Activate()
    Set_All_Charts
End Sub
 
Private Sub Chart_Deactivate()
    Reset_All_Charts
End Sub

This code turns on chart events for the chart sheet itself and for all charts embedded in the chart sheet when the sheet is activated, then turns off chart events when the sheet is deactivated. If your program executes additional code in the Chart_Activate and _Deactivate events, include the lines above with the other code, in the order that works best for your application.

3. Workbook Events to Enable All Charts On All Sheets In One Workbook

Remove the Worksheet_Activate, Worksheet_Deactivate, Chart_Activate, and Chart_Deactivate code that enables chart events for specific worksheets or chart sheets. These procedures are rendered redundant by the following Workbook_SheetActivate and _SheetDeactivate event procedures.

You must trap the Activate and Deactivate events for all sheets (worksheets and chart sheets) in the desired workbook, and use these events to run the Set_All_Charts and Reset_All_Charts procedures. Right-click the small Excel icon to the left of the File menu, and choose View Code from the pop up menu to open the VBE. It opens the code module with the caption ChartEvents.xls – ThisWorkbook (Code). Choose Workbook on the left dropdown, SheetActivate from the right dropdown, and type the line Set_All_Charts inside the Workbook_SheetActivate procedure stub. Then choose SheetDeactivate from the right dropdown, and type the line Reset_All_Charts inside the Workbook_SheetDeactivate procedure stub. You now see the following in the code module:

Option Explicit
 
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Set_All_Charts
End Sub
 
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    Reset_All_Charts
End Sub

This code turns on chart events for all charts embedded in the newly activated sheet, and for the sheet itself if it’s a chart sheet, then turns off chart events when the sheet is deactivated. If your program executes additional code in the Workbook_SheetActivate and _SheetDeactivate events, include the lines above with the other code, in the order that works best for your application.

4. Application Events to Enable All Charts on All Sheets In All Workbooks

You must trap the Activate and Deactivate events for all sheets (worksheets and chart sheets) in any workbook, and the Activate and Deactivate events for all workbooks, and use these events to run the Set_All_Charts and Reset_All_Charts procedures. This process is a little more involved than using sheet or workbook events because you must create a class module to detect application events.

To create the Application Event Class Module, switch to the VB Editor to create a new class module. Make sure the ChartClassEvents.xls workbook is selected in the Project Explorer window. In the VBE, choose Insert menu > Class Module. A new code module opens with the caption ChartClassEvents.xls – Class1 (Code). If the Properties window is not open, choose View menu > Properties or press the F4 function key. In the Properties window, change the class name to CAppEvent (following the convention that the name of a class module begins with a capital C). Now declare an Application type object with event trapping enabled, by adding this line in the Declarations section of the class module.

Public WithEvents EventApp As Excel.Application

After adding this line, the class module contains the EventApp item in the left dropdown, in addition to (General) and Class. Select EventApp from the left dropdown, and select in turn SheetActivate, SheetDeactivate, WorkbookActivate, and WorkbookDeactivate from the right dropdown. Insert the line Set_All_Charts in the Activate event procedures, and Reset_All_Charts in the Deactivate event procedures. The CAppEvent class module should now contain this code:

Option Explicit
 
Public WithEvents EventApp As Excel.Application
 
Private Sub EventApp_SheetActivate(ByVal Sh As Object)
    Set_All_Charts
End Sub
 
Private Sub EventApp_SheetDeactivate(ByVal Sh As Object)
    Reset_All_Charts
End Sub
 
Private Sub EventApp_WorkbookActivate(ByVal Wb As Workbook)
    Set_All_Charts
End Sub
 
Private Sub EventApp_WorkbookDeactivate(ByVal Wb As Workbook)
    Reset_All_Charts
End Sub

You must create an instance of the application class before it will respond to events. To activate the application event class, in the MChartEvents module, add a declaration line:

Dim clsAppEvent As New CAppEvent

Insert the following procedures into the MChartEvents module. The first tells the class that it is responding to events in the current application, and enables events in the active sheet’s charts. The second tells the class that it is responding to events in Nothing (no events!), and disables events in the active sheet’s charts.

Sub InitializeAppEvents()
  Set clsAppEvent.EventApp = Application
  Set_All_Charts
End Sub
 
Sub TerminateAppEvents()
  Set clsAppEvent.EventApp = Nothing
  Reset_All_Charts
End Sub

The last step in activating application-level events is to run the InitializeAppEvents procedure. You could use a command bar button or menu command for this, but those approaches both require the user to remember to go click something. Since you now are an expert on events, you can use workbook events to activate the application events.

The application events and chart events class modules likely reside within an add-in or workbook you’ve built to trap events from the entire application. Open the ThisWorkbook code module for your workbook. If your program is a regular workbook, use the dropdowns at the top of the code module to insert Workbook_Open and Workbook_BeforeClose procedures, and enter InitializeAppEvents and TerminateAppEvents where appropriate, as shown below:

Private Sub Workbook_Open()
    InitializeAppEvents
End Sub
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    TerminateAppEvents
End Sub

If your program is an add-in, use the dropdowns at the top of the code module to insert Workbook_AddinInstall and Workbook_AddinUninstall procedures, and enter InitializeAppEvents and TerminateAppEvents where appropriate, as shown below:

Private Sub Workbook_AddinInstall()
    InitializeAppEvents
End Sub
 
Private Sub Workbook_AddinUninstall()
    TerminateAppEvents
End Sub

When the workbook is opened or the add-in installed, the application event class is instantiated, so it can begin watching for chart events. When the workbook is closed or the add-in uninstalled, the application event class in terminated, and chart events are no longer trapped.

In a perfect world, this would be sufficient to keep the application event procedures working. In our programming environment, however, many things can break the application event hooks. If your program encounters a run time error, for example, you may find yourself without application events, and therefore, without chart events. You should insert the InitializeAppEvents line into other procedures where appropriate. For example, you could place it at the top or bottom of every procedure run from your program’s command bar and menu buttons.

The Final Event

In this article, you found out how useful chart events can be. They can extend the user interface of the programs you write, making it easy for users to identify points for your program to work on. With a little ingenuity, you can create powerful applications. For example, recently, I made a utility that draws a trend line for only part of a plotted series using the first and last points indicated by two mouse clicks. I made another utility that lets the user zoom in and out on the basis of mouse actions. Once you’ve experimented with chart events, you’ll think of many ways to enhance your projects.

Chart Event Articles on the Peltier Tech Blog

There are several examples that make use of chart events on this blog, including:

Chart Event to Highlight a Series

Chart Event Class Module to Highlight a Series

Highlight a Series with a Click or a Mouse Over

Accordion Chart for Jorge

Peltier Tech Chart Utility

Error Bar Ideosyncrasy

After using Excel 2007 for a while, getting used to the idea that everything had changed and we weren’t going back to 2003 ever again, I started fooling around with charts and chart elements. I began to find lots of little changes, most of them actually good ones, even if they were implemented in a funny way (at least until service packs and Excel 2010 cleaned up things).

Anyone who used my first charting utility knows things ain’t always done right the first time, and mine were tiny bits of software. I can’t imagine Microsoft’s task trying to coordinate thousands of developers and a bazillian lines of code.

One of the neat changes I discovered was that error bars were now treated as AutoShape lines, just like any lines in any shapes in Office. This means you had a lot of formatting options available to you, including nice embellishments like arrowheads on the ends of the error bar line segments. Then I forgot about it until a colleague brought it up recently.

To show this nice formatting, let’s look at a simple line chart with simple error bars. For clarity, and to avoid spoiling the story before I’m ready to tell it, I’ll start with positive error bars only.

Simple Line Chart with Simple Error Bars

Select the error bars and click Ctrl+1 (numeral one) to open the Format Error Bars task pane. In the main tab (below the bar chart icon, shown below left) change End Style from Cap to No Cap. Then on the formatting tab (below the paint can icon) check out the Begin and End Arrow Types.

This is the Format Error Bars task pane in Excel 2013; the Format Error Bars dialog in Excel 2007 and 2010 is substantially the same.

Format Error Bar Dialog

The error bar begins at the point, right? And ends at the, uh, end of the error bar, right? At least that’s what seems to make sense. So let’s pick a nice big round ball for the Begin Arrow Type.

Balls at Beginning of Error Bars

And let’s pick a nice big old arrow for the End Arrow Type. I’ve chosen the largest size for both ends of the error bar.

Arrowheads at End of Error Bars

And here’s our line chart with error bars, where the markers of the line chart could be replaced by the balls at the beginning of the error bars, and the arrows point away from the line.

Simple Line Chart with Fancy Ball and Arrowhead Error Bars

This is a very nice embellishment. I’ve used it in several projects already, and shown it to many people.

Anyway, back to the beginning of the story: the message from my colleague was that Excel 2010 and 2013 seem to define the beginnings and ends of the error bars differently.

Well, for positive error bars, Excel 2007, 2010, and 2013 all look the same.

Simple Line Chart with Simple Error Bars

But if we look at negative error bars, only Excel 2013 shows them beginning at the points and ending at the ends of the error bars, pointing downward. Excel 2007 and 2010 show the balls at the ends of the error bars and the arrowheads at the points, pointing upward. That’s bizarre.

Simple Line Chart with Simple Error Bars

Even more bizarre, if the error bars go both ways, only Excel 2013 has symmetric arrows. Excel 2010 shows both sets of arrows pointing upward, the negative ones toward the points, the positive ones away from the points. And Excel 2007 only has one set of arrows, beginning at the end of the negative error bars, ending at the ends of the positive error bars. Though if you had to, you could just pretend the end was the beginning and vice versa. Whatevs.

Simple Line Chart with Simple Error Bars

Excel 2007’s charting infrastructure was finished quickly at the end of the development cycle, so a few glitches weren’t ironed out of the final product. Excel 2010 fixed a lot of inconsistencies in Excel 2007’s charts, but these error bars show that not everything was totally fixed. In Excel 2007 or 2010 you could fake it with a second, hidden plotted series, and format two sets of error bars so they looked right. Excel 2013 has gotten the error bars working nicely, though.

Peltier Tech Chart Utility

Pivot Tables in Microsoft Excel: Links

This introduction has been contributed by Debra Dalgleish, Excel MVP. 
Contextures, Copyright © 2014. All rights reserved.
Debra Dalgleish, Excel MVP since 2001, is the author of three books on pivot tables, published by Apress. She shares Excel tips, tutorials, and videos on her websites, www.contextures.com and www.pivot-table.com.

Web Sites

Peltier Tech Blog – Pivot Table Resources – a listing of posts on this blog, covering many aspects of pivot tables in Microsoft Excel, including:

Debra Dalgleish’s Excel Tutorials and Videos - which includes these pages of Pivot Table-related topics:

Microsoft – Overview of PivotTable and PivotChart reports
Good introduction to Pivot Tables.

Microsoft – 25 Easy PivotTable Reports
Sample file to download, and on-line instructions

Microsoft – Create a Pivot Table to Analyze Worksheet Data
Basic steps, and links to other articles

Chandoo – Excel Pivot Table Tutorial
Chandoo gives a good overview of pivot tables, with helpful tips and links.

Microsoft Support Articles

Calculated field returns incorrect grand total in Excel (211470)
In a PivotTable, Microsoft Excel may calculate an incorrect grand total for a calculated field.

Pivot Table Uses COUNT Instead of SUM with Blank Cells (110599)
Microsoft Excel automatically uses the SUM function for numeric data and the COUNT function for non-numeric data

How to create a dynamic defined range in an Excel worksheet (830287)
Create a named range that extends to include new information

GETPIVOTDATA formula is automatically created (287736)
When you try to create a simple cell link formula that refers to a cell in the data area of a PivotTable in Microsoft Excel, a GETPIVOTDATA formula is automatically created instead.

You cannot create a PivotTable in Excel 2013 when field names in a source range contain similar characters (2756731)
The data model cannot differentiate between the similar characters.

Pivot Table Books

Here are a few books about pivot tables, available from Amazon and elsewhere. I’ve selected these books because I know the authors and I’ve used the books, so I can vouch for their quality. Disclosure: if you purchase one of these books using my link, I’ll get a teeny commission.

Beginning PivotTables in Excel 2007: From Novice to Professional

Microsoft Excel Most Valuable Professional Debra Dalgleish explains what PivotTables are, how you can benefit from using them, how to create them and modify them, and how to use their enhanced features. Using a Pivot Table in Microsoft Excel 2007 is a quick and exciting way to slice and dice a large amount of data. Debra carefully explains the benefits of using Pivot Tables for fast data analysis, provides a step-by-step approach to those new to Pivot Tables, and offers tips and tricks that cannot be found elsewhere.

Excel Pivot Tables Recipe Book: A Problem-Solution Approach

Debra Dalgleish, Microsoft Excel Most Valuable Professional since 2001, and an expert and trainer in Microsoft Excel, brings together a one-stop resource for anyone curious about representing, analyzing, and using their data with PivotTables and PivotCharts. Debra presents tips and techniques in this collection of recipes that can’t be found in Excel’s Help section, while carefully explaining the most confusing features of PivotTables to help you realize their powerful potential.

Excel 2013 Pivot Table Data Crunching (MrExcel Library)

This book will help you leverage all the amazing flexibility and analytical power of Pivot Tables. You will learn how to generate complex pivot reports complete with drill-down capabilities and accompanying charts. Then you’ll discover how to build a comprehensive, dynamic pivot table reporting system for any business task or function. Microsoft Excel Most Valuable Professionals Bill Jelen and Mike Alexander include step-by-step instructions, real-world case studies, plus complete and easy recipes for solving your most common business analysis problems.

Peltier Tech Chart Utility

Peltier Tech Chart Utility

 

Create Excel dashboards quickly with Plug-N-Play reports.