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. Click "Column chart" button
  3. Click "Clustered Column" chart button

Create Combo Box

  1. Go to "Developer" tab
  2. Click "Insert controls" button
  3. Click Combo Box (Form Control)
  4. Click 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. Right click on your workbook in the Project Explorer window.
  3. Click "Insert"
  4. Click "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. Right-click combo box.
  2. Click "Assign macro...".
  3. Click "SelectTable".
  4. Click OK button.

Populate Combo Box

  1. Right-click combo box.
  2. Click "Format control..." and a dialog box appears, see image below.
  3. Go to tab "Control".
  4. Click "Input range" button.
  5. Select cell range E2:E4.
  6. Click OK button.

Download Excel file through email

Enter your email address to receive the workbook. Note, an email will actually be sent to you.
* You will also get a weekly newsletter, unsubscribe anytime!