|
发表于 2024-7-4 22:37
来自手机
|
显示全部楼层
mhx0322 发表于 2024-7-4 16:42
是 .MinimumScale = minVal 出错,显示不是Axis对象
Sub SetChartAxisBasedOnRange()
Dim ws As Worksheet, i%, xmin#, xmax#
Dim cht As ChartObject, arr
' 遍历所有图表并设置横坐标轴
For Each cht In ActiveSheet.ChartObjects
'获取x轴值*****************
arr = cht.Chart.SeriesCollection(1).XValues
xmin = Application.Min(arr) 'x坐标轴最小值
xmax = Application.Max(arr) 'x坐标轴最大值
With cht.Chart.Axes(xlCategory, xlPrimary)
.MinimumScale = xmin '设置x坐标轴最小刻度
.MaximumScale = xmax '设置x坐标轴最大刻度
End With
Next cht
End Sub |
|