• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How do I convert an existing Chart to VBA Code?

cmissal

New Member
Hi,

It's been a while since I have worked with Excel VBA so I'm trying to get back up on the horse.

I created a form on worksheet "Admin" to allow user to select multiple text data sources and ingest them (different criteria depending on the file format). These files populate a table on a worksheet Data". I thought I could simply copy the "Admin" worksheet and VBA code to an existing file with the "Data" worksheet and associated "Charts" and have the data dynamically update the charts, but this failed. I attempted to recreate the VBA code and buttons in this second file but nothing worked.

So I am not trying to copy the charts from the second workbook into my original. Doing this brings the relative references from the original workbook/Sheet/ranges, (and it is a rather complicated series of charts), so I thought it would be easier to convert to VBA code and then use find-replace to modify the source data location.

Any way of doing this? (converting existing chart to VBA Code)?

Thanks!

Casey
 
I wouldn't attempt this, If your not very familiar with VBA and the Chart Object

Better to manual copy the chart and then on each series either edit the Series Function in the formula bar or Right click on the Chart and Select Data, then change the worksheet references
 
Yes @Hui, it would be challenge to make 'copy' of chart only with VBA.
In this time, I tried to give an answer that @cmissal wanted.
I also almost recommend to send that file here.
Without that file, it'll be challenge to give just needed information.
 
Thanks both of you. I am relatively familiar with VBA and have done extensive VBA charting/sparkline dashboards in the past, but that was years ago.

I figured the easiest thing would be to, as I mentioned, simply populate the data source for existing charts that were created. Not working as hoped.

I will sanitize the chart and then upload it, or i can send the original offline to one/both of you.
 
For anyone interested, I was able to solve my challenge without having to program the charts in VBA. It was rather obvious -- Instead of simply copying the 'chart' worksheet from the sample file to my new file with VBA code, I copied the 'chart' and 'data' worksheet that the chart referenced. This kept the relative references to chart source data local to file with the VBA code, and my VBA code simply populated/manipulated the data on the new 'data' worksheet.

PS. Still not sure why the VBA code would not run when copied into the file with the chart in it. all variable references were based on the active workbook, no hard coded references. I'll save that question for another day.

Special thanks to vletm!
 
Back
Top