vba 使用VBA在excel中创建饼图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4083015/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:54:59  来源:igfitidea点击:

Creating a pie-chart in excel using VBA

excelvbapie-chart

提问by Apollon1954

I am new to VBA 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.

我是 VBA 新手,正在尝试学习如何根据 Excel 电子表格上的某些值创建饼图。我知道如何制作条形图,但我想知道你们是否知道有关此的在线资源或教程。

回答by mechanical_meat

Tools-> Macro-> Record New Macroproduces this code which you can then tweak to your specific needs:

Tools-> Macro->Record New Macro生成此代码,然后您可以根据您的特定需求进行调整:

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