在Excel VBA中将数据标签从中心修改为以上

我正在尝试对我的DataLabels进行一些修改。

我希望列的宽度(向下,向上和总和)匹配文本的大小。 我还想使数据标签文字粗体显示,并且更容易看到。

有谁知道最好的方法来做到这一点给我的代码和现有的图表,我现在呢?

谢谢!

在这里输入图像说明

Sub Waterfall() ' ' Waterfall Macro ' ' Range("A7").Select Dim rngData As Range Dim intCounter As Integer Dim rngToSelect As Range Dim srs As Series Dim i As Long Set rngData = ActiveCell.CurrentRegion Set rngToSelect = Range(rngData.Cells(1, 1), rngData.Cells(rngData.Rows.Count, 1)) For intCounter = 1 To rngData.Columns.Count If rngData.Cells(1, intCounter).Value <> "Values" Then Set rngToSelect = Union(rngToSelect, Range(rngData.Cells(1, intCounter), rngData.Cells(rngData.Rows.Count, intCounter))) End If Next intCounter rngToSelect.Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=rngToSelect ActiveChart.ChartType = xlColumnStacked ActiveChart.ChartGroups(1).GapWidth = 75 ActiveChart.SeriesCollection("Blank").Select Selection.Format.Fill.Visible = msoFalse For Each srs In ActiveChart.SeriesCollection For i = 1 To UBound(srs.Values) srs.Points(i).HasDataLabel = srs.Values(i) > 0 Next i Next srs ActiveChart.SeriesCollection("Blank").DataLabels.ShowValue = False ActiveChart.SeriesCollection("Down").Interior.Color = RGB(255, 0, 0) ActiveChart.SeriesCollection("Up").Interior.Color = RGB(0, 204, 0) ActiveChart.Legend.LegendEntries(3).Select Selection.delete 'Remove Gridlines Dim axs As Axis For Each axs In ActiveChart.Axes axs.HasMajorGridlines = False axs.HasMinorGridlines = False Next Range("A1").Select End Sub 

为了将您的数据laebls文本更改为粗体尝试以下命令:

 ActiveChart.SeriesCollection("Down").DataLabels.Font.Bold = True