gpt4 book ai didi

excel - 调整工作表中每个图表中所有数据标签的宽度

转载 作者:行者123 更新时间:2023-12-04 21:02:54 27 4
gpt4 key购买 nike

我试图让代码从工作表的图表中调整所有数据标签的宽度,但我无法做到。在这里,我有应用数字格式的代码,我想将 width 属性添加到其中(它仅对 Excel 2013 有效):

Sub FormatAllCharts()
Dim ChtObj As ChartObject
For Each ChtObj In ActiveSheet.ChartObjects
With ChtObj.Chart
For i = 1 To .SeriesCollection.Count
With .SeriesCollection(i)
.ApplyDataLabels
.DataLabels.NumberFormat = "0,0;-0,0;;"
End With
Next
End With
Next
End Sub

这是更改数据标签宽度大小的代码:
ActiveChart.FullSeriesCollection(1).DataLabels.Select
ActiveChart.FullSeriesCollection(1).Points(4).DataLabel.Select
Selection.Width = 19

最佳答案

在这里,我最终找到了解决方案:

Sub FormatAllCharts()
Dim i As Long
Dim oChtObj As ChartObject

For Each oChtObj In ActiveSheet.ChartObjects
With oChtObj.Chart
For i = 1 To .SeriesCollection.Count
With .SeriesCollection(i)
.ApplyDataLabels
.DataLabels.NumberFormat = "0,0;-0,0;;"
Values_Array = .Values
For j = LBound(Values_Array, 1) To UBound(Values_Array, 1)
.Points(j).DataLabel.Width = 19
Next
End With
Next
End With
Next
End Sub

关于excel - 调整工作表中每个图表中所有数据标签的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32715554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com