我用vba excel编写了一个代码来创建一个图表。但是我无法编写代码以在同一工作表中生成多个图形,也就是说,我有4列,我想创建4个图形。
有人可以帮我完成这项任务吗?
这是我的代码:
Sub create_BarChart()
Dim myWorksheet As Worksheet
Dim mySourceData As Range
Dim myChart As Chart
Dim myShape As Shape
Dim myChartDestination As Range
Set myWorksheet = ThisWorkbook.Worksheets("corelacao")
Set myChartDestination = myWorksheet.Range("D36:H45")
Set myShape = myWorksheet.Shapes.AddChart(Excel.XlChartType.xl3DBarClustered)
Set myChart = myShape.Chart
With myChart
.SetSourceData Source:=myWorksheet.Range("B1:C32")
.ChartTitle.Text = "Analise de correlações"
.Legend.Left = 250 'posição vertical
.Legend.Width = 300 '100
.Parent.Height = 200
.Parent.Width = 269
.Parent.Left = 95
End With
With myShape
.Height = 325 ' resize
.Top = 300 ' reposition
.Left = 100 ' reposition
.Fill.ForeColor.RGB = RGB(230, 225, 220)
.Fill.Solid
End With
End Sub
答案 0 :(得分:0)
我会在数组变量中为图表指定输入范围,并通过数组查看以生成图表:
app-navbar