可以使用VBA更改XL直方图的箱宽度
我想将Excel直方图图表中的垃圾箱的宽度设置为VBA代码中的1个。我使用宏录音机来实现代码,但是某种程度上不起作用。
当我手动记录宏观更改BinStype和BinwidThvalue时,它可以正常工作,并且在下面获取代码。当我运行宏时,binstype和binwidthvalue的值不会改变。
我在做什么错?
Sub Macro1()
'
' Macro1 Macro
'
ActiveChart.Axes(xlCategory).Select
ActiveChart.ChartGroups(1).BinsType = xlBinsTypeBinSize
ActiveChart.ChartGroups(1).BinWidthValue = 1
End Sub
I want to set the width of bins in an Excel Histogram chart to 1 in vba code. I used the macro recorder to achieve the code, but somehow that doesn't work.
When I record the macro changing the BinsType and BinWidthValue by hand, it works and I get the code below. When I run the macro the values of BinsType and BinWidthValue won't change.
What am I doing wrong?
Sub Macro1()
'
' Macro1 Macro
'
ActiveChart.Axes(xlCategory).Select
ActiveChart.ChartGroups(1).BinsType = xlBinsTypeBinSize
ActiveChart.ChartGroups(1).BinWidthValue = 1
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直方图和其他最近添加的Excel图表类型(瀑布,阳光,Treemap)在VBA中的功能有限。我不能确定您的问题是否与此缺点有关;我尽可能避免使用这些图表。
如果您的垃圾箱宽度为1,也许您可以用数据制作一个枢轴表,或设置使用频率或计的计算范围来按数字列出计数。然后制作一个普通的旧列图表。
Histograms and other recently added Excel chart types (waterfall, sunburst, treemap) have limited functionality in VBA. I can't say for sure if your problem is related to this shortcoming; I avoid these charts whenever possible.
If your bin width is 1, perhaps you can make a pivot table with your data, or set up a calc range that uses FREQUENCY or COUNTIF to list counts by number. Then make a plain old column chart.