I’m creating a subprocedure to generate a gauge chart for a report. It’s running fine until I get to the point of adding a data label to the “needle” of the chart. When I run it in debug mode, it works fine but once I try to run the full macro, the data label fails to come through. No errors occur in either scenario. The section of code is under “Needle label”
'Define worksheets
Dim source_data_sheet As Worksheet
Dim chart_destination_sheet As Worksheet
'Define chart
Dim gauge_chart As Object
'Define ranges
Dim gauge_name_range As Range
Dim gauge_value_range As Range
Dim needle_name_range As Range
Dim needle_value_range As Range
Dim needle_label_range As Range
Set source_data_sheet = ThisWorkbook.Sheets("Chart Data")
Set chart_destination_sheet = ThisWorkbook.Sheets("Dashboard")
Set gauge_name_range = source_data_sheet.Range("A7")
Set gauge_value_range = source_data_sheet.Range("B8:B12")
Set needle_name_range = source_data_sheet.Range("A14")
Set needle_value_range = source_data_sheet.Range("B15:B17")
Set needle_label_range = source_data_sheet.Range("A15:A17")
left_val = 100
top_val = 100
width_val = 300
height_val = 300
Set gauge_chart = chart_destination_sheet.Shapes.AddChart2(251, xlDoughnut, left_val, top_val, width_val, height_val)
With gauge_chart.Chart
.SetSourceData gauge_value_range
'Format Chart Title
With .ChartTitle
.Text = "Labor Utilization"
With .Format.TextFrame2.TextRange.Font
.Bold = msoTrue
With .Fill
With .ForeColor
.ObjectThemeColor = msoThemeColorAccent1
.TintAndShade = -0.5
.Brightness = 0
End With
.Transparency = 0
.Solid
End With
End With
End With
'Remove legend
.Legend.Delete
'Correct orientation
.ChartGroups(1).FirstSliceAngle = 270
With .FullSeriesCollection(1)
'Add data series name
.Name = gauge_name_range
'Transparent section
With .Points(5)
With .Format
.Line.Visible = msoFalse
.Fill.Visible = msoFalse
End With
End With
'Upper Section
With .Points(4)
With .Format
.Line.Visible = msoFalse
With .Fill
With .ForeColor
.ObjectThemeColor = msoThemeColorAccent1
.TintAndShade = 0
.Brightness = 0
End With
.Transparency = 0
.Solid
End With
End With
End With
'Middle Section
With .Points(3)
With .Format
.Line.Visible = msoFalse
With .Fill
With .ForeColor
.ObjectThemeColor = msoThemeColorAccent1
.TintAndShade = 0
.Brightness = 0.4
End With
.Transparency = 0
.Solid
End With
End With
End With
'Lower Section
With .Points(2)
With .Format
.Line.Visible = msoFalse
With .Fill
With .ForeColor
.ObjectThemeColor = msoThemeColorAccent1
.TintAndShade = 0
.Brightness = 0.8
End With
.Transparency = 0
.Solid
End With
End With
End With
End With
'Add needle
.SeriesCollection.NewSeries
With .FullSeriesCollection(2)
.Name = needle_name_range
.Values = needle_value_range
.XValues = needle_label_range
.ChartType = xlPie
.AxisGroup = 2
'Transparent Section 1
With .Points(3).Format
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
'Transparent Section 2
With .Points(1).Format
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
End With
'Reorient needle
.ChartGroups(2).FirstSliceAngle = 270
'Needle label
With .FullSeriesCollection(2).Points(2)
.ApplyDataLabels
With .DataLabel
.ShowCategoryName = True
.ShowValue = False
With .Format.TextFrame2.TextRange.Font
.Bold = msoTrue
With .Fill
With .ForeColor
.ObjectThemeColor = msoThemeColorAccent1
.TintAndShade = -0.5
.Brightness = 0
End With
.Transparency = 0
.Solid
End With
End With
End With
End With
End With
gauge_chart.Fill.Visible = msoFalse
gauge_chart.Line.Visible = msoFalse
End Sub```