I'm in the process of recreating a VBA program in C# and have run into an issue while updating Series charts. I've spent an amazing amount of time on google and forums looking to find the answer to my issue for myself, but cannot seem to figure it out.
What I'm looking to do is update a series chart to look at data from a worksheet that is not where the chart is located, and update the range.
Where my issue comes in is that when updating the series chart, C# will only accept a range. However, the range that the Series chart requires contains a sheet name, and a range cannot contain text (So I'm led to believe). an example of the range I need to recreate is as follows;
=ANZ!$J$313:$J$737,ANZ!$M$313:$O$737
The code I currently have is:
CloudAllTrialsDataPage = UpdateBook.Worksheets[CloudAllTrialsChartDataPage1];
LastRow = CloudAllTrialsDataPage.Range["J:J"].Find(StartDate, Type.Missing, XlFindLookIn.xlValues, XlLookAt.xlWhole, XlSearchOrder.xlByRows, XlSearchDirection.xlNext, Type.Missing, Type.Missing, Type.Missing).Row;
FoundCell = CloudAllTrialsDataPage.Range["J:J"].Find(strDateLM, Type.Missing, XlFindLookIn.xlValues, XlLookAt.xlWhole, XlSearchOrder.xlByRows, XlSearchDirection.xlNext, Type.Missing, Type.Missing, Type.Missing).Row;
Excel.Range Range1 = CloudAllTrialsDataPage.Range["J" + FoundCell + ":J" + LastRow];
Excel.Range Range2 = CloudAllTrialsDataPage.Range["M" + FoundCell + ":O" + LastRow];
Range DataRange = CloudAllTrialsDataPage.Range[Range1].Address + CloudAllTrialsDataPage.Range[Range2].Address;
chartObject2 = CloudAllTrialsChartPage.ChartObjects(Type.Missing);
myChart = (Excel.ChartObject)chartObject2.Item("Monthly2");
myChart.Chart.SetSourceData(DataRange);
All of the code pulls correctly and works right up until the point of inserting the range into the chart. I've tried various different workarounds but always run into the issue of trying to add the sheet name to the range.
Any assistance or pointers would be most gratefully appreciated.
Thank you.
Disclaimer: I'm a layman so excuse me if any of my terminology is "incorrect".