Automating charts with 1 x-axis and multiple y-axes in VBA

  • I'm trying to automate the creation of graphs in Excel by means of a macro. I have lots of data (currently, columns A to AM). I want one graph in total, with multiple series.

    I now have code for two series, but am wondering if it is possible to make a sort of loop that loops through the data and adds a series to the chart. I hope someone can help me in the right direction.

    I currently have this:

  • Something like this?

  • You're welcome.

    It is annoying, though, that VBA code like this is sometimes necessary. You should be able to just select the X range and then, holding down the Ctrl key, add the data range. Then use the wizard and choose the chart type. The wizard, though, as is their wont, will be capricious. Sometimes it correctly creates the chart from the range, but sometimes it won't. If you get it working and then record a macro to get the code, the code often won't work the same way. This is why I avoid creating all but the simplest charts from VBA. Jon Peltier is the human wizard of this realm.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!