VBA を使用する場合は、新しいモジュールを挿入してこのコードをコピーできます。その後、セル内で=GetPointTotal( HorseCell
, RiderCell
)を使用して関数を使用できます。
Option Explicit
Function GetPointTotal(horseRange As Range, riderRange As Range)
Dim cell As Range, searchRange As Range
Dim displaySheet As Worksheet, pointSheet As Worksheet
Dim iEndRow As Integer
Dim horseCol As String, riderCol As String, pointCol As String, points As String
Dim b As Boolean
'Configuration
Set displaySheet = ThisWorkbook.Worksheets("Sheet1")
Set pointSheet = ThisWorkbook.Worksheets("Sheet2")
horseCol = "A"
riderCol = "B"
pointCol = "Q"
'EndConfiguration
iEndRow = pointSheet.Range(horseCol & 1).End(xlDown).Row
Set searchRange = pointSheet.Range(horseCol & 1 & ":" & horseCol & iEndRow)
b = False
For Each cell In searchRange
If b = True Then Exit For
If cell.Value2 = horseRange.Value2 Then
If cell.Offset(0, 1).Value2 = riderRange.Value2 Then
points = pointSheet.Range(pointCol & cell.Row).Value2
b = True
End If
End If
Next cell
GetPointTotal = points
End Function