PDA

View Full Version : Solved: Hiding and showing a chart with a cmd btn



lwolfe
06-22-2006, 02:05 PM
How can I hide and show a pie chart using a single command button, or is this even possible? I have tried using the Chart Objects but couldn't get anything to work. I have the chart embedded into the further down the same sheet but would like to make it viewable without having to scroll down to it buy using a command button at the top of the page.

XLGibbs
06-22-2006, 02:57 PM
How did you use the Chart Object and fail...you can set it's visible property to false in code..

Another option would be to create a hyperlink in a cell with the words "Go to Chart" in the cell. You can set the address of the hyperlink to the top left cell where the chart is lower down. Simply have another hyperlink near there that says "Go Back" which goes back to the top..

lwolfe
06-22-2006, 03:16 PM
when I set the visible property = true and false even with an "if statement" all I got was a flicker on the screen. I never thought of creating a hyperlink in the a cell, I guess that would serve the purpose

lwolfe
06-23-2006, 11:10 AM
I got the code to work for the cmd btn: simple but I kept banging my head against the wall:banghead:. the code is below.

Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Get Chart" Then
Worksheets(3).ChartObjects(1).Activate
CommandButton1.Caption = "Close Chart"
Worksheets(3).ChartObjects(1).Visible = True
' this is so you don't have to doulbe click to get the
Range("A1").Activate
CommandButton1.Activate
Else
If CommandButton1.Caption = "Close Chart" Then
Worksheets(3).ChartObjects(1).Visible = False
CommandButton1.Caption = "Get Chart"
End If
End If

End Sub

lwolfe
06-23-2006, 11:14 AM
I got the code to work for the cmd btn: simple but I kept banging my head against the wall:banghead:. the code is below.

Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Get Chart" Then
Worksheets(3).ChartObjects(1).Activate
CommandButton1.Caption = "Close Chart"
Worksheets(3).ChartObjects(1).Visible = True
' The following line is so you don't have to doulbe click the button to get the Chart to disappear
CommandButton1.Activate
Else
If CommandButton1.Caption = "Close Chart" Then
Worksheets(3).ChartObjects(1).Visible = False
CommandButton1.Caption = "Get Chart"
End If
End If

End Sub

Cyberdude
06-24-2006, 12:35 PM
I?m not sure what your requirements are regarding looking at the chart.
Do you want to be able to see the chart without moving the sheet? --OR?
are you willing to move the sheet to where the chart is, then go back to the original view when you finish looking at the chart?
If it?s important to not move the sheet, the visibility option is probably what you want.
If you are willing to move the sheet just temporarily to view the chart, then I strongly urge you to use the hyperlink technique. I do that a lot. Create a ?button? manually from an AutoShape (square, oval, block arrow, whatever). Use a fancy 3-D interior color. Then assign a hyperlink to it manually. Put another button near the chart for return purposes. You can drag and drop the button to any location as needed.