我是VBA的初学者,并且想要创建一个可以自动计算和格式化Axis Value的代码。但是,我在代码中遇到错误" Order = Len(Int(Maxi))"。 Erroe消息是"需要变量。无法分配给此表达式"。感谢是否有人可以提供帮助。感谢。
埃里克
Sub ChangeAllCharts()
Dim ChtObj As ChartObject
Dim Maxi As Double
Dim xMax As Double
Dim i As Integer
Dim Order As Integer
Dim Round As Integer
For Each ChtObj In ActiveSheet.ChartObjects
'(A) Format Primary Axis Data Label
With ChtObj.Chart.Axes(xlValue).TickLabels.Font
.Size = 9
.Color = vbBlack
.Name = "Infiniti Brand"
.Bold = False
End With
'(B) Calculate Axis Value base on the Chart Dataset
With ChtObj.Chart
For i = 0 To .SeriesCollection.Count - 1
'Get the Max values of the data in the chart
Maxi = Application.Max(.SeriesCollection(i + 1).Values)
Order = Len(Int(Maxi))
Round = -1 * (Order - 1)
xMax = WorksheetFunction.RoundUp(Maxi, Round + 1)
Next i
End With
'(C) Set Axis Value
With ChtObj.Chart.Axes(xlValue)
.MaximumScale = xMax
.MinimumScale = 0
End With
Next
End Sub