Here's the solution that I came up with. Is there a better way?
vb Code:
Public Sub setSeriesLength() Dim oShtData As Excel.Worksheet Dim oSeries As Excel.Series Dim rng As String Dim tRng As String Dim tempRng As String Dim strAlpha() As String oShtData = CType(oExcel.Workbooks(1).Worksheets("data"), Excel.Worksheet) Dim rows As Integer = oShtData.UsedRange.Rows.Count tRng = "A2:A" & rows rng = "" For Each oCht As Excel.Chart In oExcel.Workbooks(1).Charts Dim cnt As Integer = CType(oCht.SeriesCollection, Excel.SeriesCollection).Count rng = "" For i As Integer = 1 To cnt oSeries = oCht.SeriesCollection(i) tempRng = CType(oCht.SeriesCollection, Excel.SeriesCollection).Item(i).Formula strAlpha = tempRng.Trim.Split("$"c) If strAlpha(0).ToLower.Contains("data") Then tempRng = strAlpha(UBound(strAlpha) - 1) & "2:" & strAlpha(UBound(strAlpha) - 1) & rows If (Len(rng) > 0) Then rng = rng & "," & tempRng Else rng = tempRng End If oSeries.Values = oShtData.Range(rng) oSeries.XValues = oShtData.Range(tRng) End If Next oCht.SetSourceData(oShtData.Range(tRng & "," & rng), Excel.XlRowCol.xlColumns) Next End Sub




Reply With Quote