Resize points in scatterplot depending on values

Schadenfreud

New Member
Joined
Jan 22, 2014
Messages
29
1-X2rlAO6hvitfuIaByXqH7wOsD_3XG3wzQIKbVh4CM2kF9-XAlUHqMk5tO-av4YOg=s800


I have this chart and I'm trying to resize its points depending on the 'Size' values [D2:D8]. I found some code that should resize the points depending on some values, but it gives me 'Run time error 91 object variable or with block not set'.

Here's the said code:
Code:
Sub ChangeScatterplotSizeMarker()


Dim rngSizes As Range
Dim lngIndex As Long


' range containing marker size
Set rngSizes = Range("D2:D8")


With ActiveChart
    With .SeriesCollection(1) <-- error 91 here
        For lngIndex = 1 To .Points.Count
            With .Points(lngIndex)
                 .MarkerSize = rngSizes.Cells(lngIndex).Value
                 .MarkerBackgroundColorIndex = _
                 rngSizes.Cells(lngIndex).Interior.ColorIndex
                 .MarkerForegroundColorIndex = _
                 rngSizes.Cells(lngIndex).Interior.ColorIndex
            End With
        Next
    End With
End With


End Sub
I'm using that code in Book1.xlsx - Sheet1 (Code), so I'm assuming it should be able to find the chart... but it might not be the case. Suggestions, solutions, help please?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
1-X2rlAO6hvitfuIaByXqH7wOsD_3XG3wzQIKbVh4CM2kF9-XAlUHqMk5tO-av4YOg=s800

I'm using that code in Book1.xlsx - Sheet1 (Code), so I'm assuming it should be able to find the chart...

??

If the chart is not selected you have to reference the chart.

What's the name of the chart?
... or, if you don't know the name of the chart (?), how many are there in worksheet Sheet1, do you know its index?
(name is the obvious choice)
 
Upvote 0
Another question, do you need a special marker? A bubble chart is exactly what you need, a scatter chart with specified marker sizes.
 
Upvote 0
Code:
Sub SizeMarker()


Dim rngSizes As Range
Dim lngIndex As Long


' range containing marker size
Set rngSizes = Sheet5.Range("G41:G47")


With Sheet5.ChartObjects(1).Chart
    For lngIndex = 1 To .SeriesCollection.Count
        With .SeriesCollection(lngIndex).Points(1)
             .MarkerSize = rngSizes.Cells(lngIndex).Value
        End With
    Next
End With


End Sub

This is what I needed, it turned out that the points are in separate 'SeriesCollections', the regular points re-size properly, but the custom ones don't for some reason.
 
Last edited:
Upvote 0
I may be wrong but I don't think you can resize them. The way I've done is to resize the source shape before applying it to the point.
 
Upvote 0
This is an example that replaces the markers with stars with growing sizes

Add 1 scatter chart to Sheet1 with 1 series and execute:

Code:
Sub AddCustomMarkers()
Dim ws As Worksheet
Dim cht As Chart
Dim shp As Shape
Dim j As Long

Set ws = Worksheets("Sheet1")
Set cht = ws.ChartObjects(1).Chart
Set shp = ws.Shapes.AddShape(msoShape6pointStar, 100, 100, 5, 5)
shp.Fill.ForeColor.RGB = vbYellow
shp.Line.ForeColor.RGB = vbGreen

With cht.SeriesCollection(1)
    For j = 1 To .Points.Count
        shp.Width = shp.Width + 2
        shp.Height = shp.Height + 2
        shp.Copy
        .Points(j).Paste
    Next j
End With

End Sub

Remark: I assumed there are no other charts in Sheet 1, else amend the index.
 
Last edited:
Upvote 0
You're using an existing shape, I need to add external images. Right now I've added all 7 images in sheet 2 range A1:A7 (I'll choose which image to use according to some criteria), but how can I use the image in Sheet2.Cell[A1] (for example), instead of the msoShape you provided?
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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