Automatically change chart data source

Mon_Star

New Member
Joined
May 12, 2016
Messages
5
Hi,

Some guidance would be appreciated. I have a performance report for each team in my workplace. I have dynamically based the charts on the one cell where I have my validation list of team names. I subsequently have a macro set up to run through the list and save the report to PDF.

I'm getting stuck at one chart where I graph as a bar chart the performance of each project the team has worked on. Each team can work on 40 projects or 20 projects, all different. I want to be able to dynamically change the entire data source of the chart based off a single cell.

I keep Googling for answers, but I just get offset answers that only reference how to automatically update a chart after adding or deleting data. I want to completely change the data source.

Help! I feel stuck

Thanks,
Mon_Star
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Here's a quick example that I ran.

Three teams named A, B, and C.
The three chart source data ranges are named DataA, DataB, and DataC.
The data validation dropdown cell is named TeamSelection, and its possible values are "A", "B", or "C".
Code:
Sub ChangeActiveChartDataSource()
''' Allows user to select chart source data through a data validation dropdown.
'''
    Dim rng As Range
    
    Select Case Range("TeamSelection").Value
        Case "A"
            Set rng = Range("DataA")
        Case "B"
            Set rng = Range("DataB")
        Case "C"
            Set rng = Range("DataC")
    End Select
    
    ActiveChart.SetSourceData Source:=rng
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top