Thanks Thanks:  0
Likes Likes:  0
Results 1 to 8 of 8

Thread: How to determine the chart name of a newly added chart

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Singapore
    Posts
    77
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    In one Spreadsheet, I use FOR loop to add several chart, the chart number varies. How can i extract the chart name of the newly added chart? Thx.

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Singapore
    Posts
    77
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is it necessary that ChartObjects(1) always refer to the chart added latestly? Seems not, So how to determine the name of the newly added chart?
    Please help.....

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Singapore
    Posts
    77
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    help please

  4. #4
    Board Regular Steve Hartman's Avatar
    Join Date
    Feb 2002
    Location
    Houston,Texas
    Posts
    417
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Right click on the chart and choose assign macro. The box that comes up will have the chart name in the top line. Cancel the box, unless of course you actually want to assign a macro to the chart.

  5. #5
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-02-27 18:41, Andrew XJ wrote:
    In one Spreadsheet, I use FOR loop to add several chart, the chart number varies. How can i extract the chart name of the newly added chart? Thx.
    If you set a chart object variable to be the new chart that has just been added, you can define the name yourself. For example:



    Dim MyChart As Chart

    For i = 1 To 5
    Set MyChart = Application.Charts.Add
    MyChart.Name = "Chart" & i
    Next



    In this example I'm just adding chart sheets rather inserting than chart objects onto sheets,
    but the same principle applies.

    _________________
    [b] Mark O'Brien

    [ This Message was edited by: Mark O'Brien on 2002-02-28 07:15 ]

  6. #6
    Guest

    Default

    These codes are for newly added codes. parts of my codes are as following:
    ActiveSheet.ChartObjects("Chart 36").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.ChartArea.Copy

    ActiveWindow.Visible = False
    Windows("Monthly Cpk Summary-PPT.xls").Activate
    Range(Cells(10 * LoopP - 15, , Cells(10 * LoopP, 13)).Select
    ActiveSheet.Paste

    'Need to determine the chart name
    ActiveSheet.ChartObjects("Chart " & LoopP + 52).Activate
    ActiveChart.PlotArea.Select
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).Delete

    I use ActiveSheet.ChartObjects("Chart "& LoopP+52).Activate because i found that the latestly creatly chart is Chart 51. So in this case how can i name the chart?
    No stuff such as "MyChart", right? so no MyChart.Name. Please enlighten.

  7. #7
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    If the whole objective is to activate the last chart that was created, add this code to your project:


    Public Sub ActivateLastChartAdded()

    Dim chrt As ChartObject
    Dim i As Integer

    For Each chrt In ActiveSheet.ChartObjects
    i = i + 1
    Next

    ActiveSheet.ChartObjects.Item(i).Activate

    End Sub


    Now to activate the last chart in your code, simply use


    ActivateLastChartAdded



    Instead of:



    ActiveSheet.ChartObjects("Chart " & LoopP + 52).Activate




    HTH
    _________________
    [b] Mark O'Brien

    [ This Message was edited by: Mark O'Brien on 2002-02-28 10:10 ]

    [ This Message was edited by: Mark O'Brien on 2002-02-28 10:13 ]

  8. #8
    New Member
    Join Date
    Mar 2017
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to determine the chart name of a newly added chart

    An easier way to find the last chart and modify it is to use the count attribute, ie

    ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Activate

    to activate the last added chart or

    ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Delete

    to remove it.

    Ex (remove all but the first two charts):

    Do While ActiveSheet.ChartObjects.Count > 2
    ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Delete
    Loop

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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