PDA

View Full Version : [SOLVED:] Stacked Chart Percentages



justdream
06-26-2020, 12:31 AM
Dears,

Could you please help me to find an automatic way to add Percentage as a Data label to my below Stacked Column chart instead of values
*Percentage already highlighted in Yellow
*We can have both Value & Percentage together
no problem but Percentage is Mandatory

mana
06-26-2020, 05:10 AM
Option Explicit


Sub test()
Dim cht As Chart
Dim rData As Range
Dim rLbl As Range
Dim ser As Series
Dim k As Long
Dim dl As DataLabels

With ActiveSheet
Set cht = .ChartObjects(1).Chart
Set rData = .Cells(1).CurrentRegion
End With

cht.ChartType = xlColumnStacked
cht.SetSourceData rData, xlColumns
cht.ApplyDataLabels

Set rLbl = Intersect(rData, rData.Offset(1, 1)).Offset(7)

For k = 1 To cht.SeriesCollection.Count
Set dl = cht.SeriesCollection(k).DataLabels
dl.Format.TextFrame2.TextRange.InsertChartField _
msoChartFieldRange, rLbl.Columns(k).Address(, , , True)
dl.ShowRange = True
dl.ShowValue = False
Next

End Sub



マナ