Link to home
Create AccountLog in
Avatar of zerog
zerogFlag for South Africa

asked on

Change data on Excel Graph from dropdown

I have an Excel workbook with 4 sheets (Terms 1, 2, 3 and 4). The last sheet has a graph. How would I get the data that plots the graph to change based on the dropdown selection (i.e. either term 1, 2, 3 or4). Sample file attached
Template_4.xlsx
Avatar of suman_g4
suman_g4
Flag of United States of America image

Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try ( in the "graph" sheet module)
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("b2")) Is Nothing Then
        With Sheets(Replace((Sheets("graph").Range("B2").Value), " ", ""))
            Set chrtdata = .Range(.Range("B1"), .Range("E" & Rows.Count).End(xlUp))
            Me.ChartObjects("Chart 1").Chart.SetSourceData Source:=chrtdata
        End With
    End If
End Sub

Open in new window

Regards
Template_4v1.xlsm
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of zerog

ASKER

Thank you Rgonzo1971 and byundt
I decided to go with the non-macro version of the solution by byundt. Thank byundt, your explanation has taught me a lot for future solutions