ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trying to add a Pie Chart (https://www.excelbanter.com/excel-programming/304222-re-trying-add-pie-chart.html)

Jon Peltier[_7_]

Trying to add a Pie Chart
 
Excel doesn't know what you mean by NewChart. Change NewChart to
OnTimeStatus or vice versa, and try again.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

jmdaniel wrote:

Keeping running into "Run Time Error 424 Object Required" error on the following code, line 4:

Sub Chart()
Dim OnTimeStatus As Chart
Set OnTimeStatus = ThisWorkbook.Charts.Add()
NewChart.Name = "On Time Status"
NewChart.ChartType = x1PieExploded
NewChart.SetSourceData Source:=Worksheets("NI Supplier Delivery Performan").Range("P1:P300")

End Sub

And how would I get the chart to show up in the actual file the data is in, instead of showing up in the file the macro is in? I assume I replace ThisWorkbook above with the name of the file, but that didn't work, perhaps because of this other issue.

Thanks.







Jon Peltier[_7_]

Trying to add a Pie Chart
 
Check the chart type. Looks like you have x1pieexploded (x-one) instead
of xlpieexploded (x-elle). You should type them all caps or all
lowercase, and if it's spelled right, the case will change. Better yet,
let Intellisense give you the list, and select the one you want.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

jmdaniel wrote:

Okay, now I get a Run Time 13 Error, Type Mismatch, on line 5.

Sub Chart()
Dim OnTimeStatus As Chart
Set OnTimeStatus = ThisWorkbook.Charts.Add()
OnTimeStatus.Name = "On Time Status"
OnTimeStatus.ChartType = x1PieExploded
OnTimeStatus.SetSourceData Source:=Worksheets("NI Supplier Delivery Performan").Range("P1:P300")

End Sub

The macro created a sheet in the file the macro is in, called "On Time Status", so it looks like the first 3 or 4 lines are working, but the help screen for this run time error isn't very helpful. Also, I am using this macro over and over, modifying another file, and actually want the chart to show up in the other file, not in the file the macro is in. I didn't find anything that tells me how to specify where the chart sheet shows up. I swear, I will be spending time with my new macro book this weekend, but I would like to get this knocked out today. Help!



"Jon Peltier" wrote:


Excel doesn't know what you mean by NewChart. Change NewChart to
OnTimeStatus or vice versa, and try again.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

jmdaniel wrote:


Keeping running into "Run Time Error 424 Object Required" error on the following code, line 4:

Sub Chart()
Dim OnTimeStatus As Chart
Set OnTimeStatus = ThisWorkbook.Charts.Add()
NewChart.Name = "On Time Status"
NewChart.ChartType = x1PieExploded
NewChart.SetSourceData Source:=Worksheets("NI Supplier Delivery Performan").Range("P1:P300")

End Sub

And how would I get the chart to show up in the actual file the data is in, instead of showing up in the file the macro is in? I assume I replace ThisWorkbook above with the name of the file, but that didn't work, perhaps because of this other issue.

Thanks.









Jon Peltier[_8_]

Trying to add a Pie Chart
 
Your code doesn't specify which workbook contains the sheet with the
data, so Excel uses the specified worksheet in the active workbook. So
replace ThisWorkbook with ActiveWorkbook.

To specify a particular workbook for the chart and for the data range,
refer to it like this:

Sub Chart()
Dim OnTimeWorkbook as Workbook
Dim OnTimeStatus As Chart
Set OnTimeWorkbook = Workbooks("MyWorkbook.xls")
Set OnTimeStatus = OnTimeWorkbook.Charts.Add()
OnTimeStatus.Name = "On Time Status"
OnTimeStatus.ChartType = x1PieExploded
OnTimeStatus.SetSourceData Source:=OnTimeWorkbook.Worksheets("NI
Supplier Delivery Performan").Range("P1:P300")
End Sub

The data and the chart can be in two different workbooks.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


jmdaniel wrote:

Thanks, Jon. Any idea on my other question, which is to have the chart show up in the file the data is in, not in the file that contains the macro?

Jeff

"Jon Peltier" wrote:


Check the chart type. Looks like you have x1pieexploded (x-one) instead
of xlpieexploded (x-elle). You should type them all caps or all
lowercase, and if it's spelled right, the case will change. Better yet,
let Intellisense give you the list, and select the one you want.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

jmdaniel wrote:


Okay, now I get a Run Time 13 Error, Type Mismatch, on line 5.

Sub Chart()
Dim OnTimeStatus As Chart
Set OnTimeStatus = ThisWorkbook.Charts.Add()
OnTimeStatus.Name = "On Time Status"
OnTimeStatus.ChartType = x1PieExploded
OnTimeStatus.SetSourceData Source:=Worksheets("NI Supplier Delivery Performan").Range("P1:P300")

End Sub

The macro created a sheet in the file the macro is in, called "On Time Status", so it looks like the first 3 or 4 lines are working, but the help screen for this run time error isn't very helpful. Also, I am using this macro over and over, modifying another file, and actually want the chart to show up in the other file, not in the file the macro is in. I didn't find anything that tells me how to specify where the chart sheet shows up. I swear, I will be spending time with my new macro book this weekend, but I would like to get this knocked out today. Help!



"Jon Peltier" wrote:



Excel doesn't know what you mean by NewChart. Change NewChart to
OnTimeStatus or vice versa, and try again.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

jmdaniel wrote:



Keeping running into "Run Time Error 424 Object Required" error on the following code, line 4:

Sub Chart()
Dim OnTimeStatus As Chart
Set OnTimeStatus = ThisWorkbook.Charts.Add()
NewChart.Name = "On Time Status"
NewChart.ChartType = x1PieExploded
NewChart.SetSourceData Source:=Worksheets("NI Supplier Delivery Performan").Range("P1:P300")

End Sub

And how would I get the chart to show up in the actual file the data is in, instead of showing up in the file the macro is in? I assume I replace ThisWorkbook above with the name of the file, but that didn't work, perhaps because of this other issue.

Thanks.











All times are GMT +1. The time now is 07:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com