Author: Oscar Cronquist Article last updated on February 25, 2019

In this article I will demonstrate how to quickly change chart data range utilizing a combobox (drop-down list). The above image shows the drop-down list and the input range is cell range E2:E4.

Cell range E2:E4 contains the table names that points to Excel defined Tables located on sheet 2011, 2010 and 2009, see picture below. When you select a table name in the drop-down list, the chart is instantly populated and refreshed, see picture above.

Excel defined Tables are great to work with, they expand automatically when new values are added, this makes charts with data sources pointing to Excel defined Tables easy to work with. You don't need to adjust the cell references when records are added or deleted.

Here are the steps to set up this scenario:

Create a chart

  1. Go to "Insert" tab
  2. Press with left mouse button on "Column chart" button
  3. Press with left mouse button on "Clustered Column" chart button

Create Combo Box

  1. Go to "Developer" tab
  2. Press with left mouse button on "Insert controls" button
  3. Press with left mouse button on Combo Box (Form Control)
  4. Press with left mouse button on and drag on the worksheet to create the combobox.

Add VBA code to a module

  1.  Press Alt + F11 to open the VB Editor.
  2. Press with right mouse button on on your workbook in the Project Explorer window.
  3. Press with left mouse button on "Insert"
  4. Press with left mouse button on "Module" to insert a module to your workbook.
  5. Copy VBA code below (Ctrl + c)
  6. Paste VBA code to the code module, see image above.
  7. Return to Excel

VBA code

'Name macro
Sub SelectTable()

'Apply actions to selected drop-down list
With ActiveSheet.Shapes(Application.Caller).ControlFormat

    'Make sure the selected drop-down list name is "Drop Down 1"
    If ActiveSheet.Shapes(Application.Caller).Name = "Drop Down 1" Then

        'Change Chart 1 data source
        Worksheets("Chart").ChartObjects("Chart 1").Chart.SetSourceData Source:= _
        Range(.List(.Value) & "[#All]")
        Worksheets("Chart").ChartObjects("Chart 1").Chart.PlotBy = xlRows
    End If
End With

End Sub

Assign macro

  1. Press with right mouse button on combo box.
  2. Press with left mouse button on "Assign macro...".
  3. Press with left mouse button on "SelectTable".
  4. Press with left mouse button on OK button.

Populate Combo Box

  1. Press with right mouse button on combo box.
  2. Press with left mouse button on "Format control..." and a dialog box appears, see image below.
  3. Go to tab "Control".
  4. Press with left mouse button on "Input range" button.
  5. Select cell range E2:E4.
  6. Press with left mouse button on OK button.

Get the Excel file


change-chart-data-range1.xlsm