Edit all Data Labels's Label Options's Label Contains together in Chart

naveyafluz

New Member
Joined
Feb 11, 2015
Messages
18
2024-08-04 08_55_48-Actual Current Loading Chart_Zhenxian - Excel.jpg

When I add Data Labels in my Chart, the Label Contains will show Value and Show Leader Lines by default. I want to change the Label Contains to show Series Name and Value instead but I have to do it one by one.

Any Excel experts know how to change it all at once to show the results as below?

2024-08-04 08_59_42-Actual Current Loading Chart_Zhenxian - Excel.jpg
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this macro. It changes the data labels for all the charts on the active sheet.

VBA Code:
Public Sub Change_Charts_Data_Labels()

    Dim ws As Worksheet
    Dim thisChartObject As ChartObject
    Dim thisSeries As Series
    Dim thisDataLabel As DataLabel
    
    Set ws = ActiveSheet
    
    For Each thisChartObject In ws.ChartObjects
        For Each thisSeries In thisChartObject.Chart.FullSeriesCollection
            thisSeries.HasDataLabels = True
            thisSeries.HasLeaderLines = False
            For Each thisDataLabel In thisSeries.DataLabels
                thisDataLabel.ShowSeriesName = True
                thisDataLabel.ShowValue = True
            Next
        Next
    Next
    
End Sub
 
Upvote 0
Try this macro. It changes the data labels for all the charts on the active sheet.

VBA Code:
Public Sub Change_Charts_Data_Labels()

    Dim ws As Worksheet
    Dim thisChartObject As ChartObject
    Dim thisSeries As Series
    Dim thisDataLabel As DataLabel
   
    Set ws = ActiveSheet
   
    For Each thisChartObject In ws.ChartObjects
        For Each thisSeries In thisChartObject.Chart.FullSeriesCollection
            thisSeries.HasDataLabels = True
            thisSeries.HasLeaderLines = False
            For Each thisDataLabel In thisSeries.DataLabels
                thisDataLabel.ShowSeriesName = True
                thisDataLabel.ShowValue = True
            Next
        Next
    Next
   
End Sub
it worked but it applies to all the charts in the sheet. How should I amend the code if I want to use this code on an active chart instead of active sheet?

I tried changing Set ws = ActiveSheet to Set ws = ActiveChart but it cannot work even on the particular chart.
 
Upvote 0
How should I amend the code if I want to use this code on an active chart instead of active sheet?

VBA Code:
Public Sub Change_Active_Chart_Data_Labels()

    Dim thisChart As Chart
    Dim thisSeries As Series
    Dim thisDataLabel As DataLabel
    
    Set thisChart = ActiveChart
    
    If Not thisChart Is Nothing Then
        For Each thisSeries In thisChart.FullSeriesCollection
            thisSeries.HasDataLabels = True
            thisSeries.HasLeaderLines = False
            For Each thisDataLabel In thisSeries.DataLabels
                thisDataLabel.ShowSeriesName = True
                thisDataLabel.ShowValue = True
            Next
        Next
    Else
        MsgBox "No chart is selected", vbExclamation
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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