• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change the source of charts using VBA codes and a Combobox control

davinosky

New Member
Hi. Chandoo, just to ask you for a little help!

I'm kind of stuck here with a grafic compounding two years and the VBA that I wrote seems not to be working properly. I Intend to visualize both years from the same source. How could i change the source of charts using VBA codes and a Combobox control? or is it somenthing else?

Here is the VBA I wrote:


Sub DropDown2_Change()

'

' DropDown2_Change Macro

'


'

Select Case Sheets("2010-11").Range("M1")

Case 1

'Sheets("grafica").Select

ActiveSheet.ChartObjects("grafica").Activate

ActiveChart.ChartArea.Select

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2010").Range("A4:F4")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2010").Range("A4:F4,A6:F6")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2010").Range("A4:F4,A6:F6,A8:F8")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2010").Range("A4:F4,A6:F6,A8:F8,A10:F10")

Case 2

'Sheets("grafica").Select

ActiveSheet.ChartObjects("grafica").Select

ActiveChart.ChartArea.Select

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2011").Range("A4:F4")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2011").Range("A4:F4,A6:F6")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2011").Range("A4:F4,A6:F6,A8:F8")

ActiveChart.SetSourceData Source:=Sheets(" V-C-I 2011").Range("A4:F4,A6:F6,A8:F8,A10:F10")

End Select


End Sub


Thanks a lot for your continuous support!
 
Hi davinosky ,


I'm new to this forum , and thought I'd start posting. Please let me know if I am wrong.


Your VBA code is changing the chart depending on whether the range M1 in sheet "2010-11" contains 1 or 2. If M1 contains 1 , then the data is taken from the sheet " V-C-I 2010" ; if M1 contains 2 , then the data is taken from the sheet " V-C-I 2011".


Now you need to find a way to insert a drop-down ListBox or ComboBox control in your sheet "2010-11" , which will populate the cell M1 with the value 1 or 2 depending on what the user selects from the ListBox or ComboBox control. Have you written the VBA code for this ?


Narayan
 
Back
Top