This works for me:
Public Function GETMATCHES(ByVal match As String, ByVal cells As Range, ByVal columnOffset As Integer) As String
Dim result As String
Dim cell As Range
For Each cell In cells
If cell.Value2 = match Then
result = result & "," & cell.Offset(0, columnOffset).Value2
End If
Next
If Len(result) > 0 Then
result = Right(result, Len(result) - 1)
End If
GETMATCHES = result
End Function
I used it like this:
=GETMATCHES(B2,$B$2:$B$7,-1)
1
solved Return list of integer values next string values