Okay, now I have an update. I've learned about using Points(i). In the first point of the series which is in the rank and percentile table, I search for the value in the original data set to find the row number. Then I check in the third column to see if the device passed or not. Once I check that, I use .MarkerForegroundColor to change the colour of the point. However, whether it passes or not, all the points in the scatter plot are turned black.
Private Sub getData_Click()
'delete everything on sheet
Cells.Select
Selection.Delete
Range("A1").Select
Dim sht As Worksheet
Dim deviceLabel As String
Dim dataLabel As String
Dim deviceNumber As String
Dim deviceCounter As Integer
Dim multiply As Integer
Dim inputRange As Range
Dim outputRange As Range
Dim numberOfRows As Integer
Dim chrt As ChartObject
Dim xRange As Range
Dim yRange As Range
Dim s As Series
Dim xLabel As String
deviceLabel = "Device #"
dataLabel = "Ron (mOhm)"
deviceCounter = 12
multiply = 1
xLabel = "Ron (mOhm)"
Set sht = ThisWorkbook.Worksheets("Limits")
Cells(10, 1) = deviceLabel
Cells(10, 2) = dataLabel
Cells(10, 3) = "Did the device pass overall?"
deviceNumber = sht.Cells(deviceCounter, 1).Value
While deviceNumber <> ""
Cells(deviceCounter - 1, 1) = deviceNumber
Cells(deviceCounter - 1, 2) = sht.Cells(deviceCounter, 2).Value * multiply
Cells(deviceCounter - 1, 3) = sht.Cells(deviceCounter, 19).Value
deviceCounter = deviceCounter + 1
deviceNumber = sht.Cells(deviceCounter, 1).Value
Wend
numberOfRows = Cells(Rows.Count, 1).End(xlUp).Row
Set inputRange = Range(Cells(11, 2), Cells(numberOfRows, 2))
Set outputRange = Cells(10, 6)
Application.Run "ATPVBAEN.XLAM!Rankperc", inputRange, outputRange, _
"C", False
Set xRange = Range(Cells(11, 7), Cells(numberOfRows, 7))
Set yRange = Range(Cells(11, 9), Cells(numberOfRows, 9))
Set chrt = ActiveSheet.ChartObjects.Add _
(Left:=586, Width:=400, Top:=250, Height:=300)
chrt.Chart.ChartType = xlXYScatter
index1 = chrt.Index
Set s = chrt.Chart.SeriesCollection.NewSeries
With s
.XValues = xRange
.Values = yRange
.Name = label
End With
With chrt.Chart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = xLabel
.Axes(xlValue, xlPrimary).TickLabels.NumberFormat = "0%"
.Axes(xlCategory).CrossesAt = -300000
End With
Dim crt As Chart
Dim val As Long
Dim pnt As point
Dim deviceValue As Long
Dim deviceFind As Boolean
Dim devicerow As Integer
devicerow = 10
Set crt = ActiveChart
For i = 1 To s.Points.Count + 10
deviceFind = False
While devicerow <= s.Points.Count + 10 And deviceFind = False
devicerow = devicerow + 1
If Cells(devicerow, 2).Value = Cells(i + 10, 7).Value Then
deviceFind = True
End If
Wend
Cells(devicerow, 4) = deviceFind
If Cells(devicerow, 3).Value = "Yes" Then
Set pnt = s.Points(i)
pnt.MarkerForegroundColor = 3
pnt.MarkerBackgroundColor = 3
End If
If Cells(devicerow, 3).Value = "No" Then
Set pnt = s.Points(i)
pnt.MarkerForegroundColor = 3
pnt.MarkerBackgroundColor = 3
End If
devicerow = 10
Next i
End Sub
Bookmarks