Extract data labels from a chart in PowerPoint to Excel

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












Would like to check if anyone here is able to simplify the following code.
What it does: Extract data labels value from a chart in powerpoint to excel.



Sub Extract_Datalabels3()
'Goal: To extract datalabels of Chart's series collection and write to excel
'Working

Dim sh As Shape
Dim sld As slide
Dim chtnow As Chart


Dim x As Integer
Dim z As Integer

Dim xlApp As New Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlworksheet As Excel.Worksheet


Set xlWorkbook = xlApp.Workbooks.Add
Set xlworksheet = xlWorkbook.Worksheets.Add
xlApp.Visible = True

Set chtnow = ActiveWindow.Selection.ShapeRange(1).Chart

z = ActiveWindow.Selection.ShapeRange(1).Chart.SeriesCollection(1).DataLabels.Count

For x = 1 To z
xlWorkbook.Sheets(1).Range("A" & x).Value = chtnow.SeriesCollection(1).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("B" & x).Value = chtnow.SeriesCollection(2).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("C" & x).Value = chtnow.SeriesCollection(3).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("D" & x).Value = chtnow.SeriesCollection(4).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("E" & x).Value = chtnow.SeriesCollection(5).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("F" & x).Value = chtnow.SeriesCollection(6).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("G" & x).Value = chtnow.SeriesCollection(7).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("H" & x).Value = chtnow.SeriesCollection(8).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("I" & x).Value = chtnow.SeriesCollection(9).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("J" & x).Value = chtnow.SeriesCollection(10).DataLabels(x).Text
Next

End Sub






share|improve this question

















  • 2




    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
    – Zeta
    Jun 8 at 7:38
















up vote
3
down vote

favorite












Would like to check if anyone here is able to simplify the following code.
What it does: Extract data labels value from a chart in powerpoint to excel.



Sub Extract_Datalabels3()
'Goal: To extract datalabels of Chart's series collection and write to excel
'Working

Dim sh As Shape
Dim sld As slide
Dim chtnow As Chart


Dim x As Integer
Dim z As Integer

Dim xlApp As New Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlworksheet As Excel.Worksheet


Set xlWorkbook = xlApp.Workbooks.Add
Set xlworksheet = xlWorkbook.Worksheets.Add
xlApp.Visible = True

Set chtnow = ActiveWindow.Selection.ShapeRange(1).Chart

z = ActiveWindow.Selection.ShapeRange(1).Chart.SeriesCollection(1).DataLabels.Count

For x = 1 To z
xlWorkbook.Sheets(1).Range("A" & x).Value = chtnow.SeriesCollection(1).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("B" & x).Value = chtnow.SeriesCollection(2).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("C" & x).Value = chtnow.SeriesCollection(3).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("D" & x).Value = chtnow.SeriesCollection(4).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("E" & x).Value = chtnow.SeriesCollection(5).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("F" & x).Value = chtnow.SeriesCollection(6).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("G" & x).Value = chtnow.SeriesCollection(7).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("H" & x).Value = chtnow.SeriesCollection(8).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("I" & x).Value = chtnow.SeriesCollection(9).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("J" & x).Value = chtnow.SeriesCollection(10).DataLabels(x).Text
Next

End Sub






share|improve this question

















  • 2




    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
    – Zeta
    Jun 8 at 7:38












up vote
3
down vote

favorite









up vote
3
down vote

favorite











Would like to check if anyone here is able to simplify the following code.
What it does: Extract data labels value from a chart in powerpoint to excel.



Sub Extract_Datalabels3()
'Goal: To extract datalabels of Chart's series collection and write to excel
'Working

Dim sh As Shape
Dim sld As slide
Dim chtnow As Chart


Dim x As Integer
Dim z As Integer

Dim xlApp As New Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlworksheet As Excel.Worksheet


Set xlWorkbook = xlApp.Workbooks.Add
Set xlworksheet = xlWorkbook.Worksheets.Add
xlApp.Visible = True

Set chtnow = ActiveWindow.Selection.ShapeRange(1).Chart

z = ActiveWindow.Selection.ShapeRange(1).Chart.SeriesCollection(1).DataLabels.Count

For x = 1 To z
xlWorkbook.Sheets(1).Range("A" & x).Value = chtnow.SeriesCollection(1).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("B" & x).Value = chtnow.SeriesCollection(2).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("C" & x).Value = chtnow.SeriesCollection(3).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("D" & x).Value = chtnow.SeriesCollection(4).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("E" & x).Value = chtnow.SeriesCollection(5).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("F" & x).Value = chtnow.SeriesCollection(6).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("G" & x).Value = chtnow.SeriesCollection(7).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("H" & x).Value = chtnow.SeriesCollection(8).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("I" & x).Value = chtnow.SeriesCollection(9).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("J" & x).Value = chtnow.SeriesCollection(10).DataLabels(x).Text
Next

End Sub






share|improve this question













Would like to check if anyone here is able to simplify the following code.
What it does: Extract data labels value from a chart in powerpoint to excel.



Sub Extract_Datalabels3()
'Goal: To extract datalabels of Chart's series collection and write to excel
'Working

Dim sh As Shape
Dim sld As slide
Dim chtnow As Chart


Dim x As Integer
Dim z As Integer

Dim xlApp As New Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlworksheet As Excel.Worksheet


Set xlWorkbook = xlApp.Workbooks.Add
Set xlworksheet = xlWorkbook.Worksheets.Add
xlApp.Visible = True

Set chtnow = ActiveWindow.Selection.ShapeRange(1).Chart

z = ActiveWindow.Selection.ShapeRange(1).Chart.SeriesCollection(1).DataLabels.Count

For x = 1 To z
xlWorkbook.Sheets(1).Range("A" & x).Value = chtnow.SeriesCollection(1).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("B" & x).Value = chtnow.SeriesCollection(2).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("C" & x).Value = chtnow.SeriesCollection(3).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("D" & x).Value = chtnow.SeriesCollection(4).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("E" & x).Value = chtnow.SeriesCollection(5).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("F" & x).Value = chtnow.SeriesCollection(6).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("G" & x).Value = chtnow.SeriesCollection(7).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("H" & x).Value = chtnow.SeriesCollection(8).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("I" & x).Value = chtnow.SeriesCollection(9).DataLabels(x).Text
Next

For x = 1 To z
xlWorkbook.Sheets(1).Range("J" & x).Value = chtnow.SeriesCollection(10).DataLabels(x).Text
Next

End Sub








share|improve this question












share|improve this question




share|improve this question








edited Jun 8 at 10:15









200_success

123k14143399




123k14143399









asked Jun 8 at 7:32









Gerald Tow

162




162







  • 2




    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
    – Zeta
    Jun 8 at 7:38












  • 2




    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
    – Zeta
    Jun 8 at 7:38







2




2




Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
– Zeta
Jun 8 at 7:38




Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. Also, you could add a little bit more detail how the extracted data should get represented.
– Zeta
Jun 8 at 7:38










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Would this work instead of all the loops:



For a = 1 To 10
For x = 1 To z
xlWorkbook.Sheets(1).Cells(x, a) = chtnow.SeriesCollection(a).DataLabels(x).Text
Next
Next a


  • do not use Interger in VBA - https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long


  • do not use variable names like a, z, x, but give them some meaningful names. E.g. x can be row or rows, thus the code would be easier to get.






share|improve this answer























  • Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
    – Gerald Tow
    Jun 8 at 9:53











  • @GeraldTow - you are welcome.
    – Vityata
    Jun 8 at 9:58










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196098%2fextract-data-labels-from-a-chart-in-powerpoint-to-excel%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Would this work instead of all the loops:



For a = 1 To 10
For x = 1 To z
xlWorkbook.Sheets(1).Cells(x, a) = chtnow.SeriesCollection(a).DataLabels(x).Text
Next
Next a


  • do not use Interger in VBA - https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long


  • do not use variable names like a, z, x, but give them some meaningful names. E.g. x can be row or rows, thus the code would be easier to get.






share|improve this answer























  • Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
    – Gerald Tow
    Jun 8 at 9:53











  • @GeraldTow - you are welcome.
    – Vityata
    Jun 8 at 9:58














up vote
1
down vote













Would this work instead of all the loops:



For a = 1 To 10
For x = 1 To z
xlWorkbook.Sheets(1).Cells(x, a) = chtnow.SeriesCollection(a).DataLabels(x).Text
Next
Next a


  • do not use Interger in VBA - https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long


  • do not use variable names like a, z, x, but give them some meaningful names. E.g. x can be row or rows, thus the code would be easier to get.






share|improve this answer























  • Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
    – Gerald Tow
    Jun 8 at 9:53











  • @GeraldTow - you are welcome.
    – Vityata
    Jun 8 at 9:58












up vote
1
down vote










up vote
1
down vote









Would this work instead of all the loops:



For a = 1 To 10
For x = 1 To z
xlWorkbook.Sheets(1).Cells(x, a) = chtnow.SeriesCollection(a).DataLabels(x).Text
Next
Next a


  • do not use Interger in VBA - https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long


  • do not use variable names like a, z, x, but give them some meaningful names. E.g. x can be row or rows, thus the code would be easier to get.






share|improve this answer















Would this work instead of all the loops:



For a = 1 To 10
For x = 1 To z
xlWorkbook.Sheets(1).Cells(x, a) = chtnow.SeriesCollection(a).DataLabels(x).Text
Next
Next a


  • do not use Interger in VBA - https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long


  • do not use variable names like a, z, x, but give them some meaningful names. E.g. x can be row or rows, thus the code would be easier to get.







share|improve this answer















share|improve this answer



share|improve this answer








edited Jun 8 at 10:36


























answered Jun 8 at 9:22









Vityata

167115




167115











  • Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
    – Gerald Tow
    Jun 8 at 9:53











  • @GeraldTow - you are welcome.
    – Vityata
    Jun 8 at 9:58
















  • Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
    – Gerald Tow
    Jun 8 at 9:53











  • @GeraldTow - you are welcome.
    – Vityata
    Jun 8 at 9:58















Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
– Gerald Tow
Jun 8 at 9:53





Thanks Vityata for getting me to the right direction. This works, I just changed .Cells(x,1) to .Cells(x,a) so that it will write on the next column in excel instead of overwriting on column 1 as it loop through the series collection.
– Gerald Tow
Jun 8 at 9:53













@GeraldTow - you are welcome.
– Vityata
Jun 8 at 9:58




@GeraldTow - you are welcome.
– Vityata
Jun 8 at 9:58












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196098%2fextract-data-labels-from-a-chart-in-powerpoint-to-excel%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation