Consulting

Results 1 to 6 of 6

Thread: Solved: Hiding and showing a chart with a cmd btn

  1. #1
    VBAX Regular
    Joined
    Jun 2006
    Posts
    10
    Location

    Solved: Hiding and showing a chart with a cmd btn

    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.

  2. #2
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    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..
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  3. #3
    VBAX Regular
    Joined
    Jun 2006
    Posts
    10
    Location
    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

  4. #4
    VBAX Regular
    Joined
    Jun 2006
    Posts
    10
    Location
    I got the code to work for the cmd btn: simple but I kept banging my head against the wall. the code is below.
    [VBA]
    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
    [/VBA]

  5. #5
    VBAX Regular
    Joined
    Jun 2006
    Posts
    10
    Location
    I got the code to work for the cmd btn: simple but I kept banging my head against the wall. the code is below.
    [VBA]
    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
    [/VBA]

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •