+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    07-24-2009
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    13

    Selecting Different Chart types

    Hi,

    I am trying to figure out a way to switch between different chart types - eg column, bar, line, etc. I have decided that the easiest way is to create all these charts and stack them on top of each other. Next I need a macro that will allow me to select the chart type and it will bring that chart to the top of the pile. At the moment I have created Buttons and assigned a macro to each button for the different chart.

    So the first button has this macro assigned to it:

    Code:
    Sub Macro2()
    
        ActiveSheet.ChartObjects("Chart 1").BringToFront
        
    End Sub
    where Chart 1 is a line chart that I have created.

    And the second button has this macro
    Code:
    Sub Macro3()
    
    ActiveSheet.ChartObjects("Chart 2").BringToFront
    
    End Sub
    And Chart 2 is a column chart.

    This does work however I would like to use a listbox rather than all these buttons but I cannot figure out how to write one macro that will switch between the various charts. Anyone have any ideas on how to do this?

    Thanks
    Last edited by D'Artagnan; 08-09-2009 at 01:56 PM.

  2. #2
    Forum Contributor
    Join Date
    06-14-2008
    Posts
    149

    Re: Selecting Different Chart types

    Hi,

    1. Create the list box.
    2. Right click on the list box and select "Format Control".
    3. In the "Input Range" specify a range of cells where you should have the values to show in the list box.
    4. In "Cell Link" specify a cell where a value will be posted when you click the list box. "D1" in my example macro.
    5. Right click on the list box and select "Assign Macro".
    6. Enter the name of the macro. " ShowChart" in my example.

    And here is the example macro. change the chart names / no. of charts as required:


    Code:
    Sub ShowChart()
    Dim i As Integer
    i = ActiveSheet.Range("D1").Value
    Select Case i
      Case 1
        ActiveSheet.ChartObjects("Chart 1").BringToFront
      Case 2
        ActiveSheet.ChartObjects("Chart 2").BringToFront
      Case 3
        ActiveSheet.ChartObjects("Chart 3").BringToFront
    End Select
    End Sub
    I hope I made myself clear.

    One note: I am using Excel 2007. The procedure to format the control and assign a macro may be slightly different.

    Regards.
    Last edited by se1429; 08-09-2009 at 08:35 AM.
    Welcome to: http://www.exceldigest.com/myblog/
    "Excel help for the rest of us"

  3. #3
    Registered User
    Join Date
    07-24-2009
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Selecting Different Chart types

    Brilliant, that works great. Thxs a million!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0