chart display using buttons

paulinenj

New Member
Joined
Oct 2, 2006
Messages
25
I have one sheet of data that refers to multiple other sheets of data. From that one sheet I am creating charts with drop down lists to select the cases the individual wants to use. I have 3 different charts that I need to make and I would like to put them on the same sheet, so as not to confuse the vlookup with different drop downs. I would like to make one chart visible at a time, using a button (or some other tool) to change the chart being displayed. :confused:
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

Hope this may get you going. It is a commandbutton from the controls toolbar. In the code, there is only 1 chart on the sheet. If you change the index to refer to the specific chart you could also change the caption on the button to suit.

Code:
Private Sub CommandButton1_Click()
  Sheets("sheet1").ChartObjects(1).Visible = Not (Sheets("sheet1").ChartObjects(1).Visible)
  If Sheets("sheet1").ChartObjects(1).Visible Then
    res = "Hide"
  Else
    res = "Show"
  End If
  CommandButton1.Caption = "Chart1 " & res
End Sub


Tony
 

paulinenj

New Member
Joined
Oct 2, 2006
Messages
25
Thanks,

I am just getting familiar with this code....what does "res" refer to? and does "ChartObjects(1)" just refer to the chart on that page?
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
HI

res is a variable that is used to house the Hide / Show text for the button caption.

chartobject(1) refers to the chart on that sheet. If there is only 1 chart, then it will select it. If there are multiple charts, then it will select one of them. That is why I suggested you get the name of the chart, and use it instead of the index.


Tony
 

Watch MrExcel Video

Forum statistics

Threads
1,113,992
Messages
5,545,375
Members
410,679
Latest member
rolandbianco
Top