VBA在图表上显示值(条形图)

时间:2017-12-15 13:39:42

标签: vba excel-vba charts excel

这是我正在使用的代码

Dim ejex As String, ejey As String
Dim graficos As String
Worksheets("Sheet1").Activate

ejex = "C" + CStr(cont) + ":" + "C" + CStr(conta)
ejey = "K" + CStr(cont) + ":" + "N" + CStr(conta)

graficos = ejex & "," & ejey

Dim rng As Range
Dim cht As Object

Set rng = ActiveSheet.Range(graficos)
Set cht = ActiveSheet.Shapes.AddChart

cht.Chart.SetSourceData Source:=rng

enter image description here

这是预期的图表 enter image description here

无论如何在这张图上的每个条上绘制这些值吗?我实际上是在图表上添加带有excel的文本框,我想通过宏添加它们,因为图表是自动的,并且每次宏都有效时可能会改变

1 个答案:

答案 0 :(得分:0)

您需要为每个绘制的系列添加数据标签

...
cht.Chart.SetSourceData Source:=rng

Dim ser As Series
For Each ser In cht.Chart.FullSeriesCollection
    ser.ApplyDataLabels
Next