Referencing a variable for series XValues and Values.

rdormond

New Member
Joined
Jun 1, 2015
Messages
11
Howdy, my code asks for a user to input (not shown in code below) an initial row and column (R1, C1) and final row and column (R2, C2) for the data I want to graph.

The data will all share the same XValues and differ in their Y-values. At least that's what I want to happen. I can't get past the seriescollection.XValules at all and I couldn't find the solution I was looking for online, so hopefully you can help!

Code:
Dim R1, R2, C1, C2, i, x As Integer
Dim sh As Worksheet
Dim chrt As Chart

Set sh = ActiveWorkbook.Worksheets("Sheet2")
Set chrt = sh.Shapes.AddChart.Chart

i = 1

With chrt


        .ChartType = xlXYScatter


        For x = R1 To R2
            .SeriesCollection.NewSeries[INDENT=2]' what am I doing wrong here?[/INDENT]
            .SeriesCollection(i).XValues = _
                sh.Range(Cells(R1 - 1, C1), Cells(R1 - 1, C2 - 1)).Select


            .SeriesCollection(i).Values = _
                sh.Range(Cells(x, C1), Cells(x, C2 - 1)).Select
    
            i = i + 1 
        Next x
End With
 
Semi-solved. Although I would still love to get some feedback. On my approach and how I might be able to be more efficient.

Code:
.SeriesCollection(i).XValues = _
                "='Sheet2'!R" & R1 - 1 & "C" & C1 & " : R" & R1 - 1 & "C" & C2 - 1 & ""
                
.SeriesCollection(i).Values = _
            "='Sheet2'!R" & x & "C" & C1 & " : R" & x & "C" & C2 - 1 & ""
 
Upvote 0

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