BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
Hi - I am using the following code to generate a chart, which almost works 100% fine...
There are three slight things I need to change:
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?
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:
- 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?