On Apr 4, 9:59*pm, OssieMac <Ossie...@discussions.microsoft.com>
wrote:
> Hi cate,
>
> The numeric suffix of the chart names continues to increment until you close
> the workbook and re-open it. If you create 3 charts in a freshly opened
> workbook then their names will be Chart 1, Chart 2 and chart 3.
>
> If you then delete them all and create another one before closing the
> workbook, then it will be Chart 4.
>
> I am suspecting that your question relates to being able to reference the
> charts after they are created and if so, you need to assign names to the
> charts at the time of creating.
>
> The following code example creates a charts and names it. If you are
> creating several charts then you can use a loop and concatenate "Chart" with
> the loop variable for the chart name or you might even want to give them a
> more meaningful name.
>
> Sub CreateCharts()
> Dim rngChrtPos As Range
> Dim ws As Worksheet
> Dim chrtObj As ChartObject
>
> Set ws = Sheets("Sheet1")
> Set rngChrtPos = ws.Range("D2:G12")
>
> With rngChrtPos
> * Set chrtObj = ws.ChartObjects.Add _
> * * * (.Left, .Top, .Width, .Height)
>
> * chrtObj.Name = "Chart 1"
>
> End With
>
> With chrtObj.Chart
> * .SetSourceData ws.Range("A1:B14")
> * .ChartType = xlLineMarkers
> End With
>
> End Sub
>
> --
> Regards,
>
> OssieMac
thank you. And you suspect correctly.
|