Adding a Series to a Scatter Plot Based on Conditional Check

rschappe

New Member
Joined
Jun 4, 2014
Messages
6
Hello All,

Bare with me here :)

I have 3 columns:
| A | X | Y |
| 0 | 59 | 61 |
|20 | 58 | 60 |

|110| 58 | 60 |


I want to add a series (a subset of data from columns X and Y) to my scatter plot based only on rows where the value in column A is <101.
(The subset I want is Bolded above)

This is way over my head.

A little help would be much appreciated.

Thanks in advance.

Robert
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Bump. Hello again. I have experimented a little but have had no luck.

Any helpful leads would be greatly appreciated.
 
Upvote 0
So, I have made a little progress...

Code:
 shtName = ActiveSheet.Name

' check for values < 101
    Dim notps As Integer
    Dim lowtps As Integer
    
    tps = Range("B2").Value
    lowtps = Range("B3").Value
    
    If tps > 0 Or lowtps > 0 Then
        'Set Ranges
        Dim XRng As Range
        Dim YRng As Range
        Dim LastRow As Long
        Dim i As Long
    
        LastRow = Cells(Rows.Count, "G").End(xlUp).Row
        
        For i = 1 To LastRow
            If Cells(i, "G").Value < 101 Then
                If XRng Is Nothing Then
                    Set XRng = Cells(i, "U")
                    Set YRng = Cells(i, "V")
                Else
                    Set XRng = Union(XRng, Cells(i, "U"))
                    Set YRng = Union(YRng, Cells(i, "V"))
                End If
            End If
        Next i
    End If

' add scatterplot
    Charts.Add
    With ActiveChart
        .ChartType = xlXYScatter
        .SetSourceData Source:=Range( _
        "'" + shtName + "'!U:V")
        .HasLegend = False
        .SeriesCollection(1).HasDataLabels = False
        .Location Where:=xlLocationAsObject, Name:=statSht
        .FullSeriesCollection(2).XValues = XRng
        .FullSeriesCollection(2).Values = YRng
    End With

My code fails at the second to last line.

Runtime error '-2147221080 (800401a8)
The specified dimension is not valid for the current chart type

Thoughts?
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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