Adding Dynamic Ranges as a Series to Scatterplot

rschappe

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

I have 3 columns:
| A | X | Y |
| 0 | 59 | 61 |
|20 | 58 | 60 |
|110| 59 | 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
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?
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,216,381
Messages
6,130,294
Members
449,570
Latest member
TomMacca52

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