I need to find all chart objects that use a particular range as a value for a sequence so that I can update them to use a different range instead.
The following is the code I already have
The comparison fails with an error; caused either by a type miss-match[13] (direct comparison) or object expected[424] (when comparing the top-left cell only)
Any enlightenment as to why the code doesn't seem to work would be greatly appreciated
The following is the code I already have
Rich (BB code):
Option Explicit
Sub testUpdateCharts()
updateCharts Range("A1:A10"), Range("B1:B10")
End Sub
Sub updateCharts(oldvals As Range, newvals As Range)
Dim chrt As Chart
'Iterate ALL the charts
For Each chrt In ThisWorkbook.Charts
updateChart chrt, oldvals, newvals
Next chrt
Dim sheet As Worksheet
For Each sheet In ThisWorkbook.Worksheets
Dim t As Variant
For Each t In sheet.ChartObjects
Set chrt = t.Chart
updateChart chrt, oldvals, newvals
Next t
Next sheet
End Sub
Sub updateChart(chrt As Chart, oldvals As Range, newvals As Range)
Debug.Print "UpdateChart: " & chrt.Name
Dim srs As Series
'Iterate all the series in the chart
For Each srs In chrt.SeriesCollection
Debug.Print "UpdateChart: " & chrt.Name & "::" & srs.Name
'If srs.Values = oldvals Then 'error 13 Type miss match
If srs.Values.Cells(1, 1) = oldvals.Cells(1, 1) Then 'errors 424 object required
Set srs.Values = newvals
End If
Next srs
Exit Sub
End Sub
The comparison fails with an error; caused either by a type miss-match[13] (direct comparison) or object expected[424] (when comparing the top-left cell only)
Any enlightenment as to why the code doesn't seem to work would be greatly appreciated