可以使用VBA更改XL直方图的箱宽度

发布于 2025-01-20 22:30:55 字数 391 浏览 3 评论 0原文

我想将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2025-01-27 22:30:55

直方图和其他最近添加的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文