1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
'Update 20150310
'Updated 6/9/16 Jay Coltrain
'Dim rng As Range
Dim xResult As String
xResult = ""
Dim Rows As Long, i As Long
Rows = pWorkRng.Rows.Count
For i = 1 To Rows
If pWorkRng.Cells(i, 1).Value = pValue Then
xResult = xResult & ", " & pWorkRng.Cells(i, 1).Offset(0, pIndex - 1)
End If
Next i
Dim varSection As Variant
Dim sTemp As String
Dim sDelimiter As String
sDelimiter = ","
For Each varSection In Split(xResult, sDelimiter)
If InStr(1, sDelimiter & sTemp & sDelimiter, sDelimiter & varSection & sDelimiter, vbTextCompare) = 0 Then
sTemp = sTemp & sDelimiter & varSection
End If
Next varSection
MYVLOOKUP = Mid(sTemp, Len(sDelimiter) + 1)
End Function |
Partager