Hi ,
I went through a lot of threads in this forum, although there were a couple relating to the same problem am facing, they didnt solve my error .. so here's my question again ..
When am trying to delink charts , i get an error stating "Unable to set the formula property of series class".
The code is as follows :
Code
Sub DelinkChartData()
Dim iCtr As Integer, iChars As Integer, SH As Shape, iPlotOrder As Integer
Dim nPts As Long, iPts As Long 'Holds the total no of points in the chart
Dim xArray, yArray, sChtName As String, sSrsName As String
Dim xVals, yVals
Dim ChtSeries As Series ' var used to loop thru the series collection
Dim ws As Worksheet
Dim sChartType As String, iCtr1 As Integer
For Each ws In ActiveWorkbook.Sheets
If Left(ws.Name, 3) = "Sch" Then
ws.Activate
For Each SH In ws.Shapes
SH.Select
If SH.Type = msoChart Then
sChtName = ActiveChart.Name
For Each ChtSeries In ActiveChart.SeriesCollection
nPts = ChtSeries.Points.Count
xArray = ""
yArray = ""
xVals = ChtSeries.XValues
yVals = ChtSeries.Values
sSrsName = ChtSeries.Name
iPlotOrder = ChtSeries.PlotOrder
For iPts = 1 To nPts
If IsNumeric(xVals(iPts)) Then
' SHORTEN NOS IN X ARRAY (REMOVING EXCESS DIGITS)
iChars = WorksheetFunction.Max(InStr(CStr(xVals(iPts)), "."), 5)
'xArray = xArray & Round(Left(CStr(xVals(iPts)), iChars), 0) & ","
xArray = xArray & Left(CStr(xVals(iPts)), iChars) & ","
Else
'PUTTING QUOTES AROUND STRING VALUES
xArray = xArray & """" & xVals(iPts) & ""","
End If
'SAME AS X (ABOVE)
iChars = WorksheetFunction.Max(InStr(CStr(yVals(iPts)), "."), 5)
'On Error Resume Next
'yArray = yArray & Round(Left(CStr(yVals(iPts)), iChars), 0) & ","
'On Error GoTo 0
''' handle missing data - replace blanks and #N/A with #N/A
If IsEmpty(yVals(iPts)) Or WorksheetFunction.IsNA(yVals(iPts)) Then
yArray = yArray & "#N/A,"
Else
' NEED TO ROUND NUMBERS ELSE THROWS ERROR yArray = yArray & Round(Left(CStr(yVals(iPts)), iChars), 0) & ","
End If
Next
'REMOVE FINAL COMMA
xArray = Left(xArray, Len(xArray) - 1)
yArray = Left(yArray, Len(yArray) - 1)
ChtSeries.Formula = "=SERIES(""" & sSrsName & """,{" & xArray & "},{" & yArray & "}," & CStr(iPlotOrder) & ")"
Next
End If
Next SH
End If
Next
End Sub
Display More
I get the error at the line "ChtSeries.Formula ". I get the error when the
Code
yArray var = "268.6 ,216.4 ,289.2 ,15.5 ,462.0 ,214.1 ,183.7,303.6 ,413.6, 353.9,314.6,403.7, 665.0,374.1,500.6, 583.5,552.6,550.8, 586.3 "
but if I had to recude the yArray var from "268.6 - 500.6", it works fine .. not sure if its got anything to do with the length of the array... Any help is highly appreciated. Thank You !