You can extract that information from the source data string using text functions. The source data is available using .SeriesCollection
:
activesheet.chartobjects("Chart 1").chart.SeriesCollection(1).Formula
will return something like this:
"=SERIES(,Sheet1!$A$1:$A$4,Sheet1!$B$1:$B$4,1)"
That contains the two columns you need, "A" and "B". You can extract them using text functions like INSTR()
, MID()
, and LEFT()
. Here is an example using debug.print to output the columns. I'm assuming you already know how to export them since that was not included in your question.
Sub FindSourceColumns()
Dim sourcedata, firstcolumn, secondcolumn As String, c as chartobject
for each c in activesheet.chartobjects
sourcedata = c.Chart.SeriesCollection(1).Formula
firstcolumn = Mid(sourcedata, InStr(sourcedata, "!$") + 2, 5)
firstcolumn = Left(firstcolumn, InStr(firstcolumn, "$") - 1)
Debug.Print firstcolumn
secondcolumn = Mid(sourcedata, InStr(InStr(sourcedata, "!$") + 2, sourcedata, "!$") + 2, 5)
secondcolumn = Left(secondcolumn, InStr(secondcolumn, "$") - 1)
Debug.Print secondcolumn
next c
End Sub