如何通过VBA在excel中创建饼图? [英] How can I create a piechart in excel by VBA?

查看:667
本文介绍了如何通过VBA在excel中创建饼图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB的新手,我正在尝试学习如何使用Excel电子表格中的某些值创建饼图。我知道怎么做条形图,但我想知道你们是否知道在线资源或教程...

谢谢。



我尝试过:



I am new to VB and am trying to learn how to create a pie chart out of certain values on the excel spreadsheet. I know how to do the bar charts but i was wondering whether you guys are aware of online resources or tutorials for this..
Thanks.

What I have tried:

Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Sheet11").Range("B4:C99"), PlotBy:= _
    xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet11"
ActiveChart.HasTitle = False

推荐答案

最简单的学习方法是记录一个手动创建饼图的宏。然后,您可以进入宏编辑器并查看已创建的代码。
The easiest way to learn is to record a macro creating the pie chart manually. You can then go into the Macro Editor and see the code that was created.


Excel具有记录用户操作并将这些操作转换为VBA代码的功能。

- 开始新的宏录制

- 做你的行动(饼图)

- 停止宏录制

- 去VBE并检查代码,然后适应集成到您的代码。
Excel have a feature that record user actions and translate those actions into VBA code.
- Start a new macro recording
- do your actions (a pie chart)
- Stop macro recording
- go to VBE and inspect code, then adapt to integrate to your code.


这篇关于如何通过VBA在excel中创建饼图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆