VBA Charts (Data Selection & Data Label Formatting)

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
969
Hi - I am using the following code to generate a chart, which almost works 100% fine...

Code:
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.david\AppData\Roaming\Microsoft\Templates\Charts\OpsReviewHistogramTemplate.crtx")

With ActiveChart
    .ChartTitle.Select
    .ChartTitle.Text = "Ball Edit Percentage"
    Selection.Format.TextFrame2.TextRange.Characters.Text = "Ball Edit Percentage" & vbCrLf & res
   
    .Axes(xlCategory).AxisTitle.Select
    .Axes(xlCategory, xlPrimary).AxisTitle.Text = "Venue"
    Selection.Format.TextFrame2.TextRange.Characters.Text = "Venue" & vbCrLf & sChartTitle2
   
    '.FullSeriesCollection(1).XValues = "='7DayEdits'!$A$2:$A$55"
    .FullSeriesCollection(1).XValues = ActiveWorkbook.ActiveSheet.Range(Cells(1, 1), Cells(1, 1).End(xlDown))
    .Axes(xlCategory).Select
    Selection.TickLabels.Orientation = xlUpward

There are three slight things I need to change:

  1. When the data is selected, for some reason it's including the header row as a data label. So, for example...for this code...Range("Sum7EditsTable[[#All],[Venue]]").SelectActiveWorkbook.Names.Add Name:="VenueColumn", RefersToR1C1:="=Sum7EditsTable[[#All],[Venue]]"

it selects not only the data UNDER the "Venue" header, but it also selects the "Venue" header as well - so when the data is populated in the chart, the first bar is titled "Venue" instead of the specific venue name.

Similarly, the very last data point is missing, because the data is starting in the wrong place.

2. Finally, the data labels I have displaying are rounding to two decimal places, not three. How do I change that? Or is it better to change it in the source data if needed?
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
969
I found both problems. The 3rd to last line of code was causing the wrong labels and the rounding was because I had the column misassigned.

Thanks,
 

Watch MrExcel Video

Forum statistics

Threads
1,122,303
Messages
5,595,324
Members
413,986
Latest member
Elizsk

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
Top