+ Reply to Thread
Results 1 to 6 of 6

Renaming a chart

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    215

    Renaming a chart

    I am new to working with charts so most of this code was discovered using macros and may be very inefficient.
    ChartName = "MyChart1"
    RangeName = "MonthR"
    Scalex = 0.7
    ImageNo = "ImageNo1"



    Sub GMCharts(ChartName, RangeName, Scalex, ImageNo)

    With Sheets("GROSSMARGIN")

    ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
    ActiveChart.SetSourceData Source:=.Range(RangeName)
    ActiveChart.Parent.Name = ChartName
    ActiveChart.ChartType = xlColumnClustered


    ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered


    ActiveChart.FullSeriesCollection(1).AxisGroup = 1
    n = ActiveChart.FullSeriesCollection.Item(1).Name
    ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered
    ActiveChart.FullSeriesCollection(2).AxisGroup = 1
    ActiveChart.FullSeriesCollection(3).ChartType = xlLine
    ActiveChart.FullSeriesCollection(3).AxisGroup = 1
    ActiveChart.FullSeriesCollection(3).ChartType = xlColumnClustered
    ActiveChart.FullSeriesCollection(3).AxisGroup = 2
    ActiveSheet.ChartObjects(ChartName).Activate
    ActiveChart.HasLegend = True
    ActiveChart.SetElement (msoElementLegendBottom)
    ActiveChart.Legend.LegendEntries(2).Delete
    If ChartName = "MyChart1" Then
    ActiveChart.ChartTitle.Text = "GrossMargin " & Sheets("GrossMargin").Range("G5").Value ………………………... 'Line with fault
    ElseIf ChartName = "MyChart2" Then
    ActiveChart.ChartTitle.Text = "GrossMargin " & Sheets("GrossMargin").Range("L5").Value
    End If
    My problem is that at the line marked as having a fault I get the message "This object has no title"
    I may have confused ChartName and ChartTitle but I am lost and need some help please

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Renaming a chart

    Just a shot in the dark, havent worked with charts in VBA yet, but worth a try, above that line
    try setting the chart "hastitle" to true like below

    ActiveChart.ChartTitle.HasTitle = True
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  3. #3
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    215

    Re: Renaming a chart

    cubangt,
    Thanks for your thoughts. No joy though just get the same error "This object has no title" on your line
    John

  4. #4
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Renaming a chart

    Can you upload a sample file so other can chime in and assist.

  5. #5
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    215

    Re: Renaming a chart

    cubangt
    I was just about to make a sample file for you when I had an idea, based on your idea.
    I had a quick look at the object browser and changed your line to "ActiveChart.HasTitle=True
    And that worked.Thanks
    John

  6. #6
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Renaming a chart

    Nice, glad you got it figured out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Renaming Chart or Table shapes in PowerPoint
    By charm1 in forum PowerPoint Programing
    Replies: 2
    Last Post: 01-31-2018, 05:11 PM
  2. Renaming Chart Objects
    By tobyst1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2015, 08:00 AM
  3. [SOLVED] Renaming a chart then Paste it as picture
    By dinesh_ltjd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2014, 07:41 AM
  4. [SOLVED] Renaming a chart, and elliminating an anomaly of chart copies given the same name by excel
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2014, 02:33 PM
  5. Renaming Chart Title as the sheet name and text
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-22-2013, 06:02 PM
  6. Pivot Pie Chart Data Label renaming
    By matpj in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-22-2007, 12:07 PM
  7. Renaming A Tab
    By mark_richards in forum Excel General
    Replies: 6
    Last Post: 10-27-2005, 11:05 AM

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.6.0 RC 1