Updating a series of charts using VBA error

yerromnitsuj

New Member
Joined
Sep 12, 2011
Messages
32
I am looping through several similar pages to update a chart on each page. I run the macro and get the error, "Unable to set the XValues property of the Series class." Here is the code:

Code:
Sub Vlookup_formula_histogram()
'
'
'
Dim State As String
Dim chtObj As ChartObject
For i = 1 To Worksheets(SheetA).Range("B3").Value 'Number of state and company combos
 
    If Worksheets(SheetB).Cells(i + 1, 6) = Worksheets(SheetA).Range("B5") Then
 
    State = Worksheets(SheetB).Cells(i + 1, 1)
 
    'Copy and drag the histogram formula
    Sheets(Worksheets(SheetB).Cells(i + 1, 1).Value).Select
    Range("S4").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],R2C69:R23C70,2)"
    Range("S4").Select
    Selection.AutoFill Destination:=Range("S4:S" & Sheets(Worksheets(SheetB).Cells(i + 1, 1).Value).Range("X3").Value + 3)
 
    For Each chtObj In Sheets(State).ChartObjects
 
        'Change the formula for the chart
        chtObj.Activate
        ActiveChart.SeriesCollection(1).XValues = "=" & State & "!R2C70:R23C70"
        ActiveChart.SeriesCollection(1).Values = "=" & State & "!R2C71:R23C71"
        'ActiveChart.HasTitle = True
        'activechart.ChartTitle.Text =
    Next
    End If
Next i
End Sub

and this line is the culprit:

Code:
ActiveChart.SeriesCollection(1).XValues = "=" & State & "!R2C70:R23C70"

Any ideas of where the problem might be coming from and how I might fix it? Thanks!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top