graphing find the X,Y of a point

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
Somebody asked me to help them with a graph. I know very little about graphing.

They have the following table:
xysizecolor
4515
2713
3927

<tbody>
</tbody>

They created a scatter chart(actually 100s of dots). Now they are asking if I can create some VBA to change the color of each dot in the scatter chart.

I wanted to try to index through the points and look up the color on the raw data but I cannot find the original x,y values in the point object to then use to lookup on the raw data.

Any suggestions?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
See if you can adapt this:

Code:
Sub Test()
    Dim i As Long
    With ActiveChart
        With .SeriesCollection(1)
            For i = 1 To .Points.Count
                .Points(i).MarkerBackgroundColorIndex = ActiveSheet.Range("D2:D4").Cells(i, 1).Value
                .Points(i).MarkerForegroundColorIndex = ActiveSheet.Range("D2:D4").Cells(i, 1).Value
            Next i
        End With
    End With
End Sub
 
Upvote 0
That was my fall back. I was hoping that I could get the X,Y of the point from the series (something like .Points(i).xValue) But I guess simply assuming the point order is right is my only option.
 
Upvote 0
The points will be in the right order. You can get the source range for the Series like this:

Code:
Sub Test()
    Dim Rng As Range
    Dim i As Long
    With ActiveChart
        With .SeriesCollection(1)
            Set Rng = Range(Split(.Formula, ",")(2))
            For i = 1 To .Points.Count
                .Points(i).MarkerBackgroundColorIndex = Rng.Cells(i, 3).Value
                .Points(i).MarkerForegroundColorIndex = Rng.Cells(i, 3).Value
            Next i
        End With
    End With
End Sub
 
Upvote 0
Thank you. As long as I am assured that the points will be in order I'm not as worried.

Thank you for the .SeriesCollection(1).Formula That lets me find it if he moves the data. I'll feel much more comfortable having asked the series where it's data is.
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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