VLookup

SammySpaceman

Board Regular
Joined
Aug 18, 2002
Messages
64
Office Version
  1. 2019
Platform
  1. Windows
Is it possible to have VLookup return more than one value at a time?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here's the UDF code

<pre>'---------------------------------------------------------------------------------------
' Procedure : MVLOOKUP
' DateTime : Ago, 20 2002 16:46
' Author : Juan Pablo González
' Purpose : Return an array of looked values the same way as VLOOKUP.
' but can handle multiple matches. Uses exact matches.
'---------------------------------------------------------------------------------------
'
Function MVLOOKUP(LookedValue As Variant, Matrix As Variant, Column As Integer) As Variant
Dim Result() As Variant
Dim i As Integer
Dim Counter As Long

If IsObject(Matrix) Then Matrix = Matrix.Value

On Error Resume Next
Do
i = i + 1
Counter = UBound(Matrix, i)
Loop Until Err.Number <> 0

If i < Column Then MVLOOKUP = CVErr(xlErrNum): Exit Function
Counter = 0

For i = LBound(Matrix, 1) To UBound(Matrix, 1)
If Matrix(i, 1) = LookedValue Then
Counter = Counter + 1
ReDim Preserve Result(1 To Counter)
Result(Counter) = Matrix(i, Column)
End If
Next i
On Error GoTo 0
If Counter = 0 Then
MVLOOKUP = CVErr(xlErrNA)
Else
MVLOOKUP = Application.Transpose(Result)
End If
End Function</pre>
 
Upvote 0
On 2002-08-20 14:40, SammySpaceman wrote:
Is it possible to have VLookup return more than one value at a time?

Sure. Here's an example...
Book1
ABCDEFG
1ApplesA10A10
2BananasB20
3GrapesC30
4OrangesD40
5
Sheet1


Note: This is an array formula which must be entered using the Control+Shift+Enter key combination. The outermost braces, { }, are not entered by you -- they're supplied by Excel in recognition of a properly entered array formula. For more on array formulas see the Excel Help topic for "About array formulas and how to enter them".
This message was edited by Mark W. on 2002-08-20 14:54
 
Upvote 0
On 2002-08-20 14:53, Mark W. wrote:
Sure. Here's an example...
Note: This is an array formula which must be entered using the Control+Shift+Enter key combination. The outermost braces, { }, are not entered by you -- they're supplied by Excel in recognition of a properly entered array formula. For more on array formulas see the Excel Help topic for "About array formulas and how to enter them".

Mhmm, now you make me wonder what does the OP mean by "multiple"...
 
Upvote 0
Hey PaddyD, you just entered a circular reference!!! :grin:
This message was edited by Mark W. on 2002-08-20 15:30
 
Upvote 0

Forum statistics

Threads
1,222,310
Messages
6,165,261
Members
451,949
Latest member
bovacik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top