load VBA data to line chart - excel

I need to feed data into a line chart with VBA. I need to give a basic unidimensional range when I do it with Excel in a raw test. The thing is that now I need to hide some things in VBA code, so that the user just sees a curve resulting of some basic input at the click of a button.
I think there are at least two options for me :
either have the chart object placed in the Excel before, and having it point to some VBA snippet. In this case, should I somehow point to VBA from Excel ? Or would VBA access the chart area by some ID ?
create everything dynamically from VBA, the chart window, the chart, and the series input. This might be trickier to figure out maybe as I have frozen panes, so there would be the question of which pane is active (I'd like to avoid to have to do Selects to select the right one)
What would you recommend ? And in either case, how to actually do it ? What type of data to put in ?
Thank you so much !

I was involved in a project a couple of years ago that might be relevant.
A report was created monthly for the organisation's management board which contained dozens of charts. It was a near full time job for a statistician to collate and process data from across the organisation that provided the source data for these charts. I was asked to automate what could be automated.
It became clear that the appearance of the chart could not be automated. The statistician and the management board's staff held regular discussions and often agreed minor changes which they thought would better present the organisation's performance.
I could automate the collection of the data, its processing and placing of the results in the ranges from which the charts got their data. The most I ever did with a chart was change the size of a source range.
What would be the parameters that would control your macro's changes to a chart? How would your macro get the determine: type of chart, nature of the axes, text, etc?
Hope these thoughts help. I could look out my notes if my experience seems particularly relevant.

Related

Excel Line Chart with separate data points for a single line

I have a weird problem that google's not being too kind on results (mostly basic things on how to create a line chart, or combination charts, neither of which I'm after).
I'm trying to automate a report we do each month, I've managed pretty well so far by having a linked excel chart and objects, I have a single sheet in excel I paste my formatted data (set format is consistent each month) then excel picks out the data, creates the charts and when opening powerpoint it reads it all in from there.
Great! Until I was given a new piece of information, there's monthly data and a yearly tally in my data, monthly data is shown with a particular "weighting" applied, year with a different one and it's this that's caused a problem.
The package that's exporting the data can't show these figures contiguously, so we have an export with all the monthly weights, then with annual weights.
So say originally we were looking at C83 to O83 for our data for this year, we're now looking at C83 to N83 and O1364.
I've tried to look at how I would add this to the chart, which currently has the reference:
='Monthly Data to Update'!$C$83:$O$83
But doing anything + or & doesn't seem to work.
So, I decided to just pull all my data in to contiguous set to reference, (so ='Monthly Data to Update'!C83 one cell, ='Monthly Data to Update'!C84 next cell and so on).
This caused a problem for future months that're empty, having 0's in them, so I updated my code to check:
=IF('Monthly Data to Update'!C83=0,NA(),'Monthly Data to Update'!C83)
And this works, my table below my chart is blank for the empty months, my chart doesn't try and plot these empty months. Hurrah!
Now, the wrinkle. The Yearly nets aren't charted but are displayed in the table (I'm not up on Excel charts so how this was originally setup, I just copied the charts from Powerpoint in to Excel and reset the data to where it needed to be before copying it back to Powerpoint as a data linked chart).
First chart I did, works fine, second chart I did it's decided to start plotting the annual net for two of the three lines = \
So, this is how my chart looks like, running off the contiguous (but wrong) data:
And this is how it looks running off the fetched contiguous (correct) data:
It's really baffling, Exceeded and Met now plot the Year to Date figure, whereas Not Met behaves as it should, and they all have the same data layout (on the right) using the same formulas (just pointing at different cells).
I am confused..
I'm hoping to keep this light and simple so have avoided using any macro's to date, so that down the line when I hand this project over to someone any maintenance should be easy to do (say add a chart) without them asking me and me then having to remember what the hell I did a few months ago.. - so if this is doable without going down that line (which, seems like it should be, given my first chart the two lines there worked fine, and one of the three in this is behaving itself).
Apologies for the long winded description, I've given full history so if there's a step further back I could've done better, then happy to fix it up there rather than where I got to.
Ah, so apparently I could've had non-contiguous data with a comma, not a plus or ampersand, so the chart data would be:
=('Monthly Data to Update'!$C$83:$N$83,'Monthly Data to Update'!$O$1404)
So I don't need to rebuild the data in to a contiguous set, and my charts don't cock up when selecting the data this way, win's all around.
Thank you for your time, hopefully this helps someone in the future. (as a saving grace for my lost morning)

Easiest way to automate the creation of charts given an input Excel file

I'd like to automate the creation of monthly reports. I have a database through which I can export an Excel file (or csv, for the record). The table format is such that the number of columns (~500) will always be the exact same, but the number of rows (25-100) is variable.
The end goal is an excel tab with a few graphs/charts based on said data. For the charts, I'll only need to use maybe 10 columns of data out of the 500, but all of the rows.
I would like to automate the creation of this report as much as possible. Ideally, it will be able to be used by people with limited Excel knowledge. I would think I could set it up such that they can export the file out of the database, input it into my created sheet, and receive an output of charts.
This seems simple but I can't find much info on something like this. I just want to tell Excel "for every inputted file, make a pie chart out of these columns, a line graph out of these columns, a bar graph out of these...etc etc"
Power Query is where I started, and it helped to clean up the large number of unneeded columns, but I don't see where the functionality to automatically create charts comes into play. Macros/VBA seemed like an obvious next step, but I'm worried about how to set it up such that other users won't have to mess with the macros to get a desired end result. Again, ideally it would be as simple as inputted a file path, clicking a button, and getting graphs outputted.
Any tips or advice on how to approach this or what Excel tools that would be easiest to use would be great. Thank you in advance!

How to print all the chart properties in Python-pptx

I have a existing chart in pptx file, i just want to update its values on daily basis, these charts are already plotted from excel and paste into pptx, i just want to modify the charts ,
but i don't know how many properties are there in charts like series, category and title properties.
i am able to print the chart series and category data, but when i modify these with chart.replace_data(chart_data)
i am getting error like below
return self._chart_part.related_parts[xlsx_part_rId]
KeyError: 'rId4'
I ma using below code to print the values ,
for series in chart.plots:
for i in series.categories:
cat_list.append(i)
for series in chart.series:
for value in series.values:
ser_list.append(value)
the graph looks like below
How can i modify such graphs with updated values which i will be passing from excel to pptx.
I suspect the problem is rooted in the "pasting from Excel" step.
One thing you can try is to right-click on the chart and choose "Edit values in Excel". If that doesn't work for any reason, that would explain the error you're seeing. If it does work, try saving and run the python-pptx code against the saved version.
An alternative, perhaps more reliable fix would be to recreate the chart natively in PowerPoint, starting from adding a new column-chart and adjusting it until you get what you see here. Then you should be able to update it daily with pretty much the code you mentioned (although your ser_list variable will accumulate values for all series in the chart if there is more than one).
To understand why this could be happening, it's important to observe that a chart does not have to have an Excel worksheet "behind" it. It can, and perhaps does in this pasting case, simply have fixed literal values that are embedded in the chart XML itself. The up-side of this is the pasting operation doesn't need to create a whole Excel spreadsheet, which might be tricky in a cut-and-paste context. The down-side is the values can't be conveniently changed using the standard methods.
I haven't tried working with one of those lately so I don't know if editing and saving the data adds a new Excel object created from the embedded values or not, but this might explain the behavior you're seeing.

Unlink chart from excel and keep data editable?

for the longest of times I've been trying to achieve this to no avail. It seems like it should be a common problem but still I haven't been able find an answer. What I want to do is:
Have a chart in Excel and/or Powerpoint.
Copy this chart as a chart object into PPT.
Keep all characteristics of the original chart but maintain it editable (i.e. - add/remove axes, data labels etc)
Break the link to the original chart/workbook but keep the data editable. I.e., I want a new excel sheet opened when I want to edit the data, just like it works if I create a new chart object.
Preferably, I would like to convert the data of the original to this new chart sheet but this is not of really high importance.
Basically, I want to be able to use graphs as templates for a new graph without editing the original data. Please help!
PS. I didn't include any code as most of the code I've tried has tried to achieve something else. I mostly want to know if this is even possible to do (it should be!)?

what is the best way to export an animated graph from excel to power point

I have created a series of graphs with excel, that all present the evolution in time of some quantities.So, behind this I have added the macro that defines the evolution of these numbers at its each specific time.
Now, I would like to present these charts on power point as well.
What is the best way to go about it?
Save all these charts as images and then create a gif ?
I would like to know the options so I don't invest too much time in one method that maybe is not the simplest.

Resources