Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding the name of a chart (Excel 200)

    I have created a chart using the chart wizard in Excel. I now want to alter that chart using VBA code. How do I find that name of the chart to get the following code to work?

    Charts("ChtNm").Activate
    ActiveSheet.SeriesCollection(1).Interior.ColorInde x = 5

    where ChtNm is the name of the chart.

    My method of the finding the chart name was to click on the chart and create a macro. This gave me the name of the macro, which is "Chart18_Click". I then assumed that the name of the chart was"Chart18". I put this into the above code. This did not work.

    Any suggestions will be greatly appreciated.

    Thanks.
    Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding the name of a chart (Excel 200)

    The Charts collection contains all chart sheets in the workbook.
    To get at a chart on a worksheet, you can use the ChartObjects collection:

    ActiveSheet.ChartObjects("Chart 18")

    You can also use the numeric index of the chart. The first chart on the active worksheet is

    ActiveSheet.ChartObjects(1)

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding the name of a chart (Excel 200)

    I think the second line should start with <code>ActiveChart</code> rather than <code>ActiveSheet</code>.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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