我找到了更新最大和最小比例圖表的方法。我調整了代碼以找到最後一行的最大比例值。下面是代碼:Excel VBA - 更新圖表比例中的錯誤
Sub ScaleAxes()
Dim LastRow, LastRow2 As Long
With ActiveChart.Axes(xlCategory, xlPrimary)
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.MaximumScale = LastRow
.MinimumScale = ActiveSheet.Range("A2").Value
End With
With ActiveChart.Axes(xlValue, xlPrimary)
LastRow2 = .Cells(.Rows.Count, "B").End(xlUp).Row
.MaximumScale = LastRow2
.MinimumScale = ActiveSheet.Range("B2").Value
End With
End Sub
但是,我得到「對象不支持此屬性或方法」錯誤。我不知道哪部分我的代碼是錯誤的。希望你們能幫助我。
哪行引發錯誤?您錯過了工作表引用的外觀 - 「.Cells」不是「Axes」類的屬性。 –
LastRow = .Cells(.Row.Count ..... line是引發錯誤信息的那一行 – Jeeva