Dynamic Excel Charts (Including Filter and VBA Methods)

In this Excel tutorial, you will learn to create dynamic Excel charts using Excel Table, Define Name Range commands, and the VBA Macro tool. In addition, we will discuss the use of OFFSET, INDEX, COUNT, and COUNTA functions. Using the Excel FILTER function, we will explain the development of dynamic filtered charts.

We have used Microsoft Office 365 while preparing the content. Although the functions and tools are applicable in the older Excel versions from Excel 2007, Microsoft introduced the FILTER function in Excel 2019.

Today is the age of information. Creating dynamic charts in Excel is an important part for professionals nowadays. We observe extensive use of data in the case of research, experiments, surveys, etc. Therefore, representing enormous data via charts is no longer a choice, it’s a necessity.

An overview image of dynamic Excel charts


Download Practice Workbook


What Is a Dynamic Excel Chart?

In Excel, the dynamic chart is a special type of chart that can be up to date automatically by nature when one or multiple rows are added or removed from the range or table. Whereas, static charts are unable to update themselves. Users can create Dynamic Charts from an Excel Table or Named Range with suitable functions such as OFFSET, INDEX, and so on.


How Many Ways to Create Dynamic Charts in Excel?

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

  1. Using Excel Table.
  2. Applying Named Range.
  3. Using VBA Macro tool.

1. Can You Make Dynamic Charts from Excel Table?

Yes, you can create dynamic charts from the Excel Table which is the easiest way. A Table in Excel automatically updates itself once new rows are added.

  • Initially, select the B4:E13 range >> Then press Ctrl + T keys to convert the range into a Table.

Inserting able from range

  • Next, select the table and select as follows: Insert tab>> Insert Column or Bar Chart command >> 2-D Clustered Column chart type.
Selecting the Clustered column chart

Click the image for details

  • Therefore, we obtain a 2-D Clustered Column chart containing sales of representatives.

Obtaining dynamic chart from Excel table

  • As you can see in the picture, inserting a row in the B14:E14 range, consequently we observe the presence of data for Marc in the following chart.

Obtaining updated dynamic excel charts after adding a new row.


2. Do Excel Functions Within Named Range Create Dynamic Charts?

Using the Named Range allows you to develop dynamic charts that respond when changes in rows or columns take place. The Named Range is generally used to group a range. We will use the OFFSET function to get the grouped range based on relative reference.

  • First to group the representatives, go to the Formulas tab >> select the Define Name command.
  • Next, type Representatives in the Name field of the Edit Name dialog.
  • Further, insert the following formula containing the OFFSET and COUNTA functions in the Refers to field >> 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

  • By following the same instructions, type Sales in the Name field of the Edit Name dialog.
  • As well as input the formula below in the Refers to field >> hit the OK command.

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

Inserting formula combining COUNTA and OFFSET functions

  • Now go to the Insert menu >> Click on the Insert Column and Bar Chart command.
  • Thus a blank chart appears >> Right-click on the blank chart >> Select the Select Data option from the context menu.
Getting the Select Data option

Click the image for details

  • Therefore, a dialog box named Select Data Source appears.
  • Then, click on the Add command from the Legend Entries(Series) field.

re-configuring the Select data source dialog

  • Next enter =NamedRange!Sales in the Series values field >> Hit the OK button.

Inputting data from the Named Range

  • Further, click on the Edit command from the Select Data Source dialog box.

re-configuring the Select Data Source dialog

  • Then, insert =NamedRange!Representatives in the Axis label range field >> Hit the OK command.

Inserting data from the Named Range

  • Finally, load the Select Data Source dialog box by clicking on the OK button.

hitting the OK button

  • Thus we obtain the chart with all the data in the C4:C13 range.

Obtaining dynamic chart in excel

  • We also navigate the presence of Marc in the chart once we insert his information in the B14:D14 range.

Updated dynamic excel charts after adding a new row.


3. How to Apply VBA Macro Tool to Develop Dynamic Charts?

By applying a simple VBA code with a Worksheet Change event, you can update your charts whenever it updates or changes the dataset such as the addition or removal of data. For instance, we are likely to insert charts for the Representatives and Sales ($) columns.

  • In the beginning, we must insert a blank chart. To do so, click as follows, Insert tab>> Insert Column or Bar Chart command >> 2-D Clustered Column chart type.

inserting a blank chart

  • Next, write 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

  • First, 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

  • Thus we get the updated charts after adding the data for Melissa in the B11:E11 range.

Updated dynamic charts after adding data of Melissa.


What Is the Way to Create Dynamic Charts Ignoring Empty Values in Excel?

You can ignore data containing blank cells from a range in the Excel charts. The procedure is almost the same as the previously mentioned approaches where we used the Named Range command. However, the previous approach doesn’t ignore the blank values. To count cells containing sales data (specifically integer), we will use the COUNT function with the INDEX function.

  • Initially, type Person in the Name field >> Insert the following formula containing INDEX and COUNT functions 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.

  • Next, type Sales(1) in the Name field >> Write 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

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

Assigning data from the Named Range

  • Finally, load the Select Data Source dialog box by hitting the OK button.

re-configuring the Select Data Source dialog

  • Therefore, we obtain 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?

If you are likely to create a filtered dynamic chart, you must use the UNIQUE function to make a drop-down list with the Data Validation tool first.

  • To begin the procedure, 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

  • Further, write 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)

Obtained the filtered dynamic excel chart using the FILTER function

  • As you can see in the image, 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.


What Are Things to Remember For Creating Dynamic Charts in Excel?

  • Excel Table to create dynamic charts with lower effort.
  • OFFSET and COUNT functions in the Named Range to create a group for the range. that helps to create dynamic charts.
  • Named Range is also applicable to avoid the blanks while creating charts.
  • Use of Data Consolidation tool, UNIQUE, and FILTER functions to develop filtered dynamic charts.

Conclusion

Throughout the tutorial, we provided a complete guideline to create dynamic Excel charts using Excel Table, Named Range, and VBA Macro tool that will be beneficial to you. Additionally, you can construct dynamic charts by applying the Named Range to ignore empty cells from the dataset. Moreover, use the filtered dynamic chart when you have a large dataset and need to filter frequently where the UNIQUE and FILTER function plays a vital role. Don’t forget to leave your thoughts in the comment section. Hope to catch you soon with some new content.


Frequently Asked Questions

Q1. What does a dynamic chart do in Excel?

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

Q2. What are dynamic charts vs static charts in Excel?

Answer: 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.

Q3. What is keyboard shortcut to create Excel charts?

Answer: 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