我想知道是否有人可以帮我创建一个宏来同时编辑多个图表的数据标签。
我目前在一张纸上有9张图表,需要将数据标签设置为格式为“Inside end”。每次我更改数据集时,我都需要单击每个单独的图表并手动将格式按到内部。看到有200多个数据集,这变得很麻烦。有没有可以做到这一点的宏?
答案 0 :(得分:1)
我不确定“内部结束”意味着什么,但您应该能够打开宏记录,单击常规步骤,然后停止记录器。您将拥有进行所述更改所需的代码。现在,只需遍历每个图表对象并进行必要的更改。
Sub LoopThroughCharts()
'PURPOSE: Loop through every graph in the active workbook
'SOURCE: www.TheSpreadsheetGuru.com/The-Code-Vault
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
cht.Activate
'Do something with the chart...
Next cht
Next sht
CurrentSheet.Activate
Application.EnableEvents = True
End Sub