Hi
What I am trying to do is match a team name from a cell in range "B8:J8" with a team name on a separate page in the range "C2:C337".
From those matches I want to determine the highest score and return that in a cell in range B20:J20
So for each team name in B8:J8 return the highest score for that team in the corresponding cell in B20:J20.
I can acheive this with a msgBox prompt however cannot with a 3rd loop to supply the answers from the highestvalue found.
What I am trying to do is match a team name from a cell in range "B8:J8" with a team name on a separate page in the range "C2:C337".
From those matches I want to determine the highest score and return that in a cell in range B20:J20
So for each team name in B8:J8 return the highest score for that team in the corresponding cell in B20:J20.
I can acheive this with a msgBox prompt however cannot with a 3rd loop to supply the answers from the highestvalue found.
Code:
Option Explicit
Sub sechigh()
Dim rngcd As Range, rnglk As Range, rngans As Range, cell1 As Range, cell2 As Range, cell3 As Range
Dim wb As Workbook
Dim wscd As Worksheet, wslk As Worksheet
Dim highestValue As Double, secondHighestValue As Double, cellval As Double
highestValue = 0
secondHighestValue = 0
cellval = 0
Set wscd = Sheets("Central Draft")
Set wslk = Sheets("Lookup")
Set rngcd = wscd.Range("B8:J8")
Set rnglk = wslk.Range("C2:C337")
Set rngans = wscd.Range("B20:J20")
For Each cell1 In rngcd
For Each cell2 In rnglk
If StrComp(cell1, cell2, vbBinaryCompare) = 0 Then
cellval = cell2.Offset(0, 2).Value
End If
If cellval < 1 And cellval > highestValue Then highestValue = cellval
Next cell2
MsgBox highestValue
Next cell1
End Sub
Last edited: