witchcraftz
New Member
- Joined
- Jan 17, 2008
- Messages
- 39
I have a code where I am pulling data from a sheet and then creating Pie charts based on the data.
My proof of concept code uses the following code and works - but is too simple since I need to create 3 charts from each line:
So I have created the following code that dynamically changes the range but it keeps giving me error 91 on the "ActiveChart.SetSourceData Source:=Range" line.
Keep in mind that this is a sample and that in reality I have 500+ lines with 3 data columns on which to create pie charts.
Here is the sample workbook:
https://drive.google.com/open?id=1bFEBIvq8IwONk5jv9DeyC7rLHEnu_Nsk
My proof of concept code uses the following code and works - but is too simple since I need to create 3 charts from each line:
Code:
With ws
.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(.Name & "!" & "D" & iRow & ":E" & iRow)
ActiveChart.ChartType = xlPie
ActiveChart.Location Where:=xlLocationAsObject, Name:="PieCharts"
End With
So I have created the following code that dynamically changes the range but it keeps giving me error 91 on the "ActiveChart.SetSourceData Source:=Range" line.
Code:
With ws
txtSource = .Name & "!" & ConvertToLetter(iCol + 16) & iRow & ":" & ConvertToLetter(iCol + 17) & iRow
.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(txtSource)
ActiveChart.ChartType = xlPie
ActiveChart.Location Where:=xlLocationAsObject, Name:=Sheet3.Name '"PieCharts"
End With
Keep in mind that this is a sample and that in reality I have 500+ lines with 3 data columns on which to create pie charts.
Here is the sample workbook:
https://drive.google.com/open?id=1bFEBIvq8IwONk5jv9DeyC7rLHEnu_Nsk
Last edited: