Re: Macro to find/return 1 or 2 highest values in Red in a spreadsheet grid
No, code in last post still not right, this should be though. Any value change within any grid or a change to AT2 will redo the font colors.
Code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x, i As Integer, d1 As Double, d2 As Double, r As Range
If Not Intersect(Target, [at2]) Is Nothing _
Or Not Intersect(Target, [Grid1]) Is Nothing _
Or Not Intersect(Target, [Grid2]) Is Nothing _
Or Not Intersect(Target, [Grid3]) Is Nothing _
Or Not Intersect(Target, [Grid4]) Is Nothing _
Or Not Intersect(Target, [Grid5]) Is Nothing _
Or Not Intersect(Target, [Grid6]) Is Nothing _
Or Not Intersect(Target, [Grid7]) Is Nothing _
Or Not Intersect(Target, [Grid8]) Is Nothing _
Or Not Intersect(Target, [Grid9]) Is Nothing Then
For i = 1 To 9
With Range("Grid" & i)
If Application.Count(.Cells) > 1 Then
d1 = Application.Large(.Cells, 1)
d2 = Application.Large(.Cells, 2)
ElseIf Application.Count(.Cells) > 0 Then
d1 = Application.Large(.Cells, 1)
d2 = 0
End If
.Cells.Font.Color = vbBlack
If [at2] > 5 Then
For Each r In .Cells
If r = d1 Or r = d2 Then r.Font.Color = vbRed
Next
Else
For Each r In .Cells
If r = d1 Then r.Font.Color = vbRed
Next
End If
End With
Next
End If
End Sub
Display More