VBA: Adding data label to chart

samahiji

Board Regular
Joined
Oct 6, 2015
Messages
82
Office Version
  1. 2019
Platform
  1. Windows
The part of code below is used to generate data label for a given data series and then color it. the code is running fine and color the data label whenever it has a value. however, when file is closed and then reopen if found that all data labels even if it is empty which creates bad chart outlook.
I need to color the datalabel that has value in it only and speed up the code little bit.

Please help.


Code:
                     With .SeriesCollection.NewSeries                    .Name = "=" & COM.Name & "!R10C3"
                    .Values = "=" & COM.Name & "!R" & 12 & "C2:R" & COM.Cells(1, 1).Value & "C2"
                    .XValues = "=" & COM.Name & "!R" & 12 & "C1:R" & COM.Cells(1, 1).Value & "C1"
                      .Border.Color = RGB(0, 102, 204)
                      .Format.Line.Weight = 0.1
                      .Format.Line.DashStyle = msoLineSysDot
                    
                    End With
    
    .SeriesCollection("CENSYS").Select
    .SeriesCollection("CENSYS").ApplyDataLabels
    .SeriesCollection("CENSYS").DataLabels.Select
    .SeriesCollection("CENSYS").DataLabels.Select
    .SeriesCollection("CENSYS").DataLabels.Format.TextFrame2.TextRange. _
        InsertChartField msoChartFieldRange, _
        "=" & COM.Name & "!R" & 12 & "C" & (Currcol + 1) & ":R" & COM.Cells(1, 1).Value & "C" & (Currcol + 1) _
        , 0
    Selection.ShowRange = True
    Selection.ShowValue = False
        Selection.Orientation = xlUpward
    Selection.Format.TextFrame2.Orientation = msoTextOrientationUpward
    Selection.Font.Size = 9
    Selection.Position = xlLabelPositionAbove
    With Selection.Format.fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 255, 0)
        .Transparency = 0.3
        .Solid
    End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I'm wondering if someone hadn't came across such issue before!
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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