ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SetSourceData Source = pivot table on same sheet (https://www.excelbanter.com/excel-programming/338989-setsourcedata-source-%3D-pivot-table-same-sheet.html)

ulfb[_2_]

SetSourceData Source = pivot table on same sheet
 
Hello
After creating a new, dynamic pivot table (contents varies) I need to add a
chart - but can´t figure out how to set the source. None of these tries work.
Help appreciated!
regards
ulf



With ActiveSheet.ChartObjects.Add _
(Left:=500, Width:=375, Top:=75, Height:=225)
' .SetSourceData Source:=ActiveSheet.PivotTables("PivotAge")
' .SetSourceData Source:=ActiveSheet.Range("C10")
' .SetSourceData Source:=.Range("C10")
.SetSourceData Source:=Sheets("Age").Range("C10")
.Chart.ChartType = xlXYScatterLines
End With

Jon Peltier[_9_]

SetSourceData Source = pivot table on same sheet
 
Your With block referenced the chart object, but .SetSourceData needs a
chart. This will work:

With ActiveSheet.ChartObjects.Add _
(Left:=500, Width:=375, Top:=75, Height:=225).Chart

.SetSourceData Source:=ActiveSheet.Range("C10")
End With

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


ulfb wrote:

Hello
After creating a new, dynamic pivot table (contents varies) I need to add a
chart - but can´t figure out how to set the source. None of these tries work.
Help appreciated!
regards
ulf



With ActiveSheet.ChartObjects.Add _
(Left:=500, Width:=375, Top:=75, Height:=225)
' .SetSourceData Source:=ActiveSheet.PivotTables("PivotAge")
' .SetSourceData Source:=ActiveSheet.Range("C10")
' .SetSourceData Source:=.Range("C10")
.SetSourceData Source:=Sheets("Age").Range("C10")
.Chart.ChartType = xlXYScatterLines
End With


ulfb[_2_]

SetSourceData Source = pivot table on same sheet
 
It certainly does. Thank you!
/ulf


"Jon Peltier" wrote:

Your With block referenced the chart object, but .SetSourceData needs a
chart. This will work:

With ActiveSheet.ChartObjects.Add _
(Left:=500, Width:=375, Top:=75, Height:=225).Chart

.SetSourceData Source:=ActiveSheet.Range("C10")
End With

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


ulfb wrote:

Hello
After creating a new, dynamic pivot table (contents varies) I need to add a
chart - but can´t figure out how to set the source. None of these tries work.
Help appreciated!
regards
ulf



With ActiveSheet.ChartObjects.Add _
(Left:=500, Width:=375, Top:=75, Height:=225)
' .SetSourceData Source:=ActiveSheet.PivotTables("PivotAge")
' .SetSourceData Source:=ActiveSheet.Range("C10")
' .SetSourceData Source:=.Range("C10")
.SetSourceData Source:=Sheets("Age").Range("C10")
.Chart.ChartType = xlXYScatterLines
End With




All times are GMT +1. The time now is 05:59 PM.

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