Custom Chart Data Labels using VBA

bahllr

Board Regular
Joined
May 7, 2009
Messages
62
I appreciate any help you all can give me. I have been playing with this for a few hours now.

I am trying to create a dynamic control chart that has 5 series (Upper Control Limit (UCL), Lower Control Limit (LCL), Average (X) and Upper Spec Limit (USL) and Lower Spec Limit (LSL).

I have dynamic named ranges for each of these five series.


I am using VBA to add a data label to the last data point each time the chart is updated. The code I am using is below. My problem is that for the USL and LSL series, I keep getting application defined or object defined errors for the 'USL' and 'LSL' labels, respectively. I am using the same code to label all 5 series and it works for 3 of the 5. Not sure why this would throw an error. Also, it allows me to name it 'L' but not 'USL/LSL'.

As you can see by series 5, I have even tried creating a link to a cell for testing. This did not work either.
Any thoughts?

For n = 1 To 5


Sheets("Results").ChartObjects("Chart 3").Activate
ActiveChart.FullSeriesCollection(n).Select
ActiveChart.FullSeriesCollection(n).Points(r).ApplyDataLabels
ActiveChart.FullSeriesCollection(n).DataLabels.Select

If n = 1 Then
Selection.NumberFormat = "#,##0.00" & " = UCL"
ElseIf n = 2 Then Selection.NumberFormat = "#,##0.00" & " = LCL"
ElseIf n = 3 Then Selection.NumberFormat = "#,##0.00" & " = X"
ElseIf n = 4 Then Selection.NumberFormat = "#,##0.00" & " = L"
ElseIf n = 5 Then Selection.DataLabel.Text = "Saturday"

End If
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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