Wednesday, February 17, 2010

http://www.excelforum.com/excel-worksheet-functions/366493-how-do-i-use-vlookup-for-multiple-occurrences-of-the-same-value.html

I am using the vlookup function to check a table which may or may not have
multiple rows for the same value of the column I am using to select. So far,
everything I have tried keeps giving me the first occurrence it finds. Do I
need to add additional parameters or should I be using something other than
vlookup?

If you have the functions in the freely downloadable file at
http:/home.pacbell.net/beban available to your workbook you can use the
VLookups function:

=VLookups(lookup_value,Lookup_table,column_reference) array entered into
enough vertical cells to accommodate the number of occurrences of
lookup_value. Or, to avoid array entering:

=Index(VLookups(lookup_value,Lookup_table,column_reference), Row(A1))
filled down as far as required.


********************************************************
Option Explicit

Public Function vlookupall$(strSearch As String, rngRange As Range, lngLookupCol As Long)

'Vlookupall searches in first column of rngRange for strSearch and returns corresponding
'values of column lngLookupCol if strSearch was found. All corr. values are collected and
'returned in one string (result of function).

Dim i As Long

If lngLookupCol > rngRange.Columns.Count Then
vlookupall = CVErr(xlErrValue)
Exit Function
End If

vlookupall = ""

For i = 1 To rngRange.Rows.Count

If rngRange(i, 1).Text = strSearch Then

vlookupall = vlookupall & rngRange(i, lngLookupCol).Text & "; "

End If

Next i

End Function
http://www.sulprobil.com/html/vlookupall.html

No comments:

Post a Comment