Change DataSource Chart VBA Range ERROR

MarceloCT

New Member
Joined
Apr 26, 2018
Messages
1
Hello Everyone!
I'm actually working on a VBA code to change the chart data source depending on the value of a cell.
My Charts are on a worksheet called "DashboardPropuesta" and my data source of the charts are on "'Base de Gráficos'".
This is the code that I am using but it keeps saying that I have a Range Error... could someone please tell me what I am doing wrong? I can't find the reason of the error.
Code:
If Not Intersect(Target, Range("B3")) Is Nothing Then
    If Range("B3").Value = "Real" Then
    ActiveSheet.ChartObjects("IEDP").Chart.SetSourceData Source:=Range("'Base de Gráficos'!A2:D9,'Base de Gráficos'!B2:D9")
    'Sheets("DashboardPropuesta").ChartObjects("IEDP").Activate
    'ActiveChart.SetSourceData Source:=Range("'Base de Gráficos'!A2:A9,'Base de Gráficos'!B2:D9")
    ElseIf Range("B3").Value = "Acumulado" Then
    Sheets("DashboardPropuesta").ChartObjects("IEDP").Chart.SetSourceData Source:=Range("'Base de Gráficos'!$A$2:$A$9,'Base de Gráficos'!$E$2:$G$9")
    End If
    End If
End Sub

I need your help! Thank you!!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hello


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ie As ChartObject, bg As Worksheet
Set bg = Sheets("Base de Gráficos")
Set ie = Me.ChartObjects("IEDP")
If Not Intersect(Target, [b3]) Is Nothing Then
    If [b3] = "Real" Then
        ie.Chart.SetSourceData bg.Range("a2:d9", "b2:d9")
        ie.Activate
        ActiveChart.SetSourceData bg.Range("a2:a9", "b2:d9")
    ElseIf [b3] = "Acumulado" Then
        ie.Chart.SetSourceData bg.Range("a2:a9", "e2:g9")
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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