Hello All,
The following MultipleLookupNoRept VBA returns duplicates for some reason beyond me. What am I doing wrong? Any help would be appreciated.
VBA:
Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer) As String
Dim addresses As Variant, values As Variant
Dim r As Long
With LookupRange.Parent
With Intersect(LookupRange.Columns(1), .UsedRange)
values = .value
addresses = .Columns(ColumnNumber).value
End With
End With
With CreateObject("System.Collections.ArrayList")
For r = 1 To UBound(values)
If values(r, 1) = Lookupvalue And r <= UBound(addresses) And addresses(r, 1) <> "" Then
.Add addresses(r, 1)
End If
Next
MultipleLookupNoRept = Join(.ToArray(), ", ")
End With
End Function
Formula in Cell:
='Project Tracker and Analyser.xlsm'!MultipleLookupNoRept.MultipleLookupNoRept(M2,'PO Report'!C:L,5)
Result:
15461, 16461, 13461, 15461, 16461, 16461, 9129, 16461, 17530, 17500, 17561, 17530 <-------Shows Duplicates
Bookmarks