如何通过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.