vba 在 Excel 中更改 X 轴比例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9848123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing X axis scale in Excel
提问by user1270123
I have a X-Y scatter plot, my values in the x axis starts from the value 30.
我有一个 XY 散点图,我在 x 轴上的值从值 30 开始。
How can i change the scale in the chart in such a way that I have values in the X axis starting from 30 and not zero?
如何更改图表中的比例,使 X 轴上的值从 30 开始而不是零?
回答by rrs
I was able to do this in VBA as follows:
我能够在 VBA 中做到这一点,如下所示:
grab the chart object:
Dim objChart As Object Set objChart = Sheets("MyWorksheetName").ChartObjects("MyChartName")
change the x-axis min value:
objChart.Chart.Axes(xlCategory).MinimumScale = myChartMinXValue
抓取图表对象:
Dim objChart As Object Set objChart = Sheets("MyWorksheetName").ChartObjects("MyChartName")
更改 x 轴最小值:
objChart.Chart.Axes(xlCategory).MinimumScale = myChartMinXValue
The x-axis in Excel charts seem to be called xlCategory
. Also NOTE the MinimumScale
property doesn't exist for all chart types. My first attempt was using xlLine
but I kept getting an error. Once I switched to xlXYScatterLines
VBA was happy.
Excel 图表中的 x 轴似乎被称为xlCategory
. 另请注意,MinimumScale
并非所有图表类型都存在该属性。我的第一次尝试是使用,xlLine
但我一直收到错误消息。一旦我切换到xlXYScatterLines
VBA 很高兴。
回答by brettdj
- right click the x-axis
- select
Format Axis
- select the
Fixed
option next toMinimum
and enter 30
- 右键单击 x 轴
- 选择
Format Axis
- 选择
Fixed
旁边的选项Minimum
并输入 30