Hi!
I have a problem where I'm trying to change the color of my different points in my scatter plot depending on a third column. Managed to get the colors right, but have no idea how to get the legend to display the different color (and if possible the content of a fourth colomn). data can look like this
0.2 0.3 1 A
0.6 0.8 1 A
0.2 0.5 3 C
0.6 0.1 2 B
0.8 0.9 1 A
0.1 0.7 4 D
...
Code for solving the plot color problem looks like follows
Sub colorXY()
Dim rngData As Range
Dim lngIndex As Long
Dim lngColor As Long
Set rngData = Worksheets("cheat1").Range("C2:C10")
With ActiveChart
With .SeriesCollection(1)
For lngIndex = 1 To .Points.Count
Select Case rngData.Cells(lngIndex, 1).Value
Case Is > 3
lngColor = RGB(0, 0, 255)
Case Is > 2
lngColor = RGB(0, 255, 0)
Case Is > 1
lngColor = RGB(255, 0, 0)
Case Else
lngColor = RGB(255, 255, 255)
End Select
With .Points(lngIndex).Format.Fill
.ForeColor.RGB = lngColor
.BackColor.RGB = lngColor
End With
Next
End With
End With
End Sub
In the above example I would like to have four entries to the legend. One for each color(column 3 (C)) and name (column 4).
Bookmarks