Name a Chart

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I am creating a chart using the following code:

VBA Code:
Sub Apply_Graph_Formatting(control As IRibbonControl)

Range("Sum7EditsTable[[#All],[Venue]]").Select
ActiveWorkbook.Names.Add Name:="VenueColumn", RefersToR1C1:="=Sum7EditsTable[[#All],[Venue]]"
Range("Sum7EditsTable[[#All],[Percent Edit]]").Select
ActiveWorkbook.Names.Add Name:="PercentColumn", RefersToR1C1:="=Sum7EditsTable[[#All],[Percent Edit]]"

ActiveWorkbook.ActiveSheet.Shapes.AddChart(201, xlColumnClustered).Select
ActiveChart.ApplyChartTemplate ("C:\Users\brian.burdette\AppData\Roaming\Microsoft\Templates\Charts\OpsReviewHistogramTemplate.crtx")
    
End Sub

However, every time I run the code to add the chart (which runs successfully), it adds the chart with a name that increases 1 each time. So the first time I created the chart is was named Chart 1, then the next time Chart 2, etc.

Once the chart is created, I need to rename it as "Edits" so I can then refer to it in code to assign a specific height and width.

I tried "Charts.Name" but it errored out. ANy ideas?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You could either rename it as shown below, or if it is the only chart on the worksheet, refer to it at ChartObjects(1)

'When a chart is on a worksheet the Name property applies to the
' ChartObject object which is the container for the Chart object. So:

VBA Code:
    With ActiveSheet.ChartObjects(1).Chart
        .Parent.Name = "Name"
    End With
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top