使用macros中的Max函数来调整图表的垂直轴

我正在尝试使用macros中的Max函数来使我的图表垂直轴自动调整到单元格范围内的最高数字。 我已经开始了一个不工作的macros,但是下面的macros是我所要做的。 任何帮助深表感谢。

ActiveSheet.ChartObjects(1).Chart.Axes(xlValue).MaximumScale = Application.WorksheetFunction.Max(Range("D26:D100")) 

下面是VBA皮特帮我想出的正确编码,再次感谢!

 ActiveSheet.ChartObjects(1).Chart.Axes(xlValue).MaximumScale = Application.WorksheetFunction.Max(Range("D26:D100")) 

对于未来的案例和良好的编码实践,尽量避免使用ActiveSheet并使用引用对象。

 Dim Sht As Worksheet Dim ChtObj As ChartObject Set Sht = Worksheets("YourSheetName") '<-- set the worksheet your charts are in Set ChtObj = Sht.ChartObjects(1) '<-- set the chart object to the specific chart object you want to modify ' now modify the chartobject properties With ChtObj .Chart.Axes(xlValue).MaximumScale = Application.WorksheetFunction.Max(Sht.Range("D26:D100")) '<-- when defining the range, also fully qualify it with the worksheet name End With