Consulting

Results 1 to 2 of 2

Thread: Stacked Chart Percentages

  1. #1

    Stacked Chart Percentages

    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
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    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

    マナ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •