Dynamic Excel Charts (Including Filter and VBA Methods)

Here’s an example of using the FILTER function for dynamic data retrieval and a chart to accompany it.

An overview image of dynamic Excel charts


Download the Practice Workbook


What Is a Dynamic Excel Chart?

In Excel, the dynamic chart is a special type of chart that updates automatically when one or multiple rows are added or removed from the range or table.


How to Create Dynamic Charts in Excel

There are 3 convenient ways to create dynamic charts in Excel. They are:

  1. Using an Excel Table.
  2. Applying a Named Range.
  3. Using VBA Macros.

Method 1 – Make Dynamic Charts from an Excel Table

  • Select the B4:E13 range.
  • Press Ctrl + T to convert the range into a Table.

Inserting able from range

  • Select the table.
  • Go to the Insert tab, select the Insert Column or Bar Chart command, and choose the 2-D Clustered Column chart type.

Selecting the Clustered column chart

  • We get a 2-D Clustered Column chart containing sales of representatives.

Obtaining dynamic chart from Excel table

  • Inserting a row in the B14:E14 range adds the data for Marc in the following chart.

Obtaining updated dynamic excel charts after adding a new row.


Method 2 – Excel Functions Within a Named Range to Create Dynamic Charts

We will use the OFFSET function to get the grouped range based on relative reference.

  • Go to the Formulas tab and select the Define Name command.
  • Type Representatives in the Name field of the Edit Name dialog.
  • Insert the following formula containing the OFFSET and COUNTA functions in the Refers to field and hit the OK button.

=OFFSET(NamedRange!$C$5,0,0,COUNTA(NamedRange!$C:$C)-1,1)

Inserting formula combining COUNTA and OFFSET functions in the Named Range

  • Make another range Sales for the following formula in the Refers to field.

=OFFSET(NamedRange!$D$5,0,0,COUNTA(NamedRange!$D:$D)-1,1)

Inserting formula combining COUNTA and OFFSET functions

  • Go to the Insert menu.
  • Click on the Insert Column and Bar Chart command.
  • A blank chart appears.
  • Right-click on the blank chart.
  • Select the Select Data option from the context menu.

Getting the Select Data option

  • A dialog box named Select Data Source appears.
  • Click on the Add command from the Legend Entries(Series) field.

re-configuring the Select data source dialog

  • Enter =NamedRange!Sales in the Series values field.
  • Hit the OK button.

Inputting data from the Named Range

  • Click on the Edit command from the Select Data Source dialog box.

re-configuring the Select Data Source dialog

  • Insert =NamedRange!Representatives in the Axis label range field.
  • Hit OK.

Inserting data from the Named Range

  • Load the Select Data Source dialog box by clicking on the OK button.

hitting the OK button

  • Here’s the chart with all the data in the C4:C13 range.

Obtaining dynamic chart in excel

  • Insert more information in the B14:D14 range.

Updated dynamic excel charts after adding a new row.


Method 3 – Apply VBA Macro Tool to Develop Dynamic Charts

  • Insert a blank chart. (go to Insert Column or Bar Chart and choose the 2-D Clustered Column chart type).

inserting a blank chart

  • Insert the following VBA code in the dedicated worksheet Module applying the VBA Worksheet Change event.
Private Sub Worksheet_Change(ByVal Target As Range)
'Developed by ExcelDemy
Dim DataRangeA As Range
Dim DataRangeC As Range
Dim CombinedRange As Range
Dim ChartObject As ChartObject
Set ws = ThisWorkbook.Sheets("VBA")
Set DataRangeA = ws.Range("C5:C" & Cells(Rows.Count, 3).End(xlUp).Row)
Set DataRangeC = ws.Range("E5:E" & Cells(Rows.Count, 5).End(xlUp).Row)
Set CombinedRange = Union(DataRangeA, DataRangeC)
If Not Intersect(Target, CombinedRange) Is Nothing Then
Set ChartObject = ws.ChartObjects("Chart 2")
ChartObject.Chart.ChartTitle.Text = "Sales Data of 2022"
ChartObject.Chart.SetSourceData CombinedRange
End If
End Sub

VBA code to make dynamic charts with VBA Change worksheet event.

Code Breakdown

  • We create a Private Sub-Procedure in the worksheet module with a Change worksheet event. For every single change, it will run the code.
Private Sub Worksheet_Change(ByVal Target As Range)
[Your Code]
End Sub
  • Set ws as a worksheet (VBA) where the code will apply. Also, assigning the values of columns C and E in the DataRangeA and DataRangeC variables.
Dim ws As Worksheet
Dim DataRangeA As Range
Dim DataRangeC As Range
Set ws = ThisWorkbook.Sheets("VBA")
Set DataRangeA = ws.Range("C5:C" & Cells(Rows.Count, 3).End(xlUp).Row)
Set DataRangeC = ws.Range("E5:E" & Cells(Rows.Count, 5).End(xlUp).Row)
  • Using the VBA UNION function, we combine columns C and D. and assign the value in the CombinedRange variable.
Dim CombinedRange As Range
Set CombinedRange = Union(DataRangeA, DataRangeC)
  • The name of the blank chart is Chart 2. The IF statement dictates if Target and CombinedRange values don’t overlap then return outcome based on ChartObject.Chart.SetSourceData properties and updates automatically.
  • ChartObject.Chart.ChartTitle.Textproperties inserts the title of the chart.
Dim ChartObject As ChartObject
If Not Intersect(Target, CombinedRange) Is Nothing Then
Set ChartObject = ws.ChartObjects("Chart 2")
ChartObject.Chart.ChartTitle.Text = "Sales Data of 2022"
ChartObject.Chart.SetSourceData CombinedRange
End If

  • We get the updated chart after adding the data for Melissa in the B11:E11 range.

Updated dynamic charts after adding data of Melissa.


Create Dynamic Charts while Ignoring Empty Values in Excel

  • Make a new Defined Name.
  • Type Person in the Name field.
  • Insert the following formula in the Edit Name dialog.

=IgnoreEmpty!$C$5:INDEX(IgnoreEmpty!$C$5:$C$11,COUNT(IgnoreEmpty!$C$5:$C$11))

Inserting formula combining INDEX and COUNT functions in the Named Range.

  • Type Sales(1) in the Name field and use the formula as follows in the Edit Name dialog.

=IgnoreEmpty!$E$5:INDEX(IgnoreEmpty!$E$5:$E$14,COUNT(IgnoreEmpty!$E$5:$E$14))

Inserting formula combining INDEX and COUNT functions in the Named Range.

Assigning data from the Named Range

  • Insert =IgnoreEmpty!Person in the Axis label range field of the Axis Labels dialog box.

Assigning data from the Named Range

  • Load the Select Data Source dialog box by hitting the OK button.

re-configuring the Select Data Source dialog

  • We get the chart containing information on the representatives and ignore the blank cells.

Getting output avoiding blanks while making dynamic Excel charts


How to Create Filtered Dynamic Charts in Excel

  • Create a unique list in the G5:G7 range by inserting the following formula containing the UNIQUE function in the G5 cell:

=UNIQUE(D5:D14)

creating the unique and drop-down list

  • Use the following formula containing the FILTER function in the B19 cell to obtain filtered data based on the selection of the drop-down list.

=FILTER(B5:E14,D5:D14=D16)

  • Create a chart by clicking on the Insert Column or Bar Chart command that we mentioned earlier.

Obtained the filtered dynamic excel chart using the FILTER function

  • By selecting TV from the drop-down list of the D16 cell, we get filtered results in the B19:E22 range as well as a Clustered Column chart.

Obtained the filtered dynamic Excel chart

Note: You will not get the FILTER function in any other versions without Microsoft Office 365, Excel 2019, and 2021.


Frequently Asked Questions

What does a dynamic chart do in Excel?

Dynamic charts in Excel update automatically once new rows containing data are added or removal of rows takes place.

What are dynamic charts vs. static charts in Excel?

Dynamic charts update automatically with the inclusion or exclusion of data from the selected range. On the other hand, static charts don’t update by employing new rows in the dataset.

What is keyboard shortcut to create Excel charts?

By selecting the dataset and pressing the Alt + F1 keys, you can create Excel charts.


Dynamic Excel Charts: Knowledge Hub


<< Go Back to Excel Charts | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!

Tags:

MD Tanvir Rahman
MD Tanvir Rahman

MD Tanvir Rahman, BUET graduate in Naval Architecture and Marine Engineering, dedicated over a year to the ExcelDemy project. He is an Excel and VBA Content Developer. Having authored 50+ insightful articles, he actively updates and improves over 80 articles, reflecting his commitment to accuracy and currency, managing day-to-day operations, and analyzing and developing Excel and VBA tutorials. His broad interests encompass Data Analysis, Advanced Excel, VBA Macro, Excel Templates, Excel Automation, and Excel Power Query, showcasing a... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo