Solved

Excel VLookup

Posted on 2011-03-09
4
311 Views
Last Modified: 2012-05-11
if there are several cases that are true down the entire column of the VLookup formula how do you make the VLookup continue (like in a loop) and return values for all true cases
0
Comment
Question by:SeeKnowledge
4 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 35085520
I typically insert a new column before the data that merges the pieces (=A1&B1) then apply the vlookup to that column.
0
 
LVL 33

Accepted Solution

by:
jppinto earned 500 total points
ID: 35085556
Here's an example of a post that handles a similar situation:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_21711567.html

jppinto
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35085585
You need a user-defined function for that, i.e. a macro-type function. Here is one that I believe Saurabh wrote:

Public Function myVLookup(value As Variant, rng As Range, retCol As String, Optional blAbs As Boolean = True) As String
Dim cl As Range, str As String
Dim intCol As Integer

If IsNumeric(retCol) Then intCol = CInt(retCol) Else intCol = Range(retCol & "1").Column

If blAbs = False Then 'returns the relative column
    
    For Each cl In rng
    
        If cl = value Then str = str & cl.Offset(0, intCol) & ", "
        
    Next

Else 'returns the absolute row (good for titles)
 
    For Each cl In rng
    
        If cl = value Then str = str & Cells(cl.Row, intCol) & ", "
        
    Next

End If

If Len(str) > 0 Then myVLookup = Left(str, Len(str) - 2) Else myVLookup = ""

End Function

Open in new window


Put it in a module of your worksheet and call it =myvlookup(a1,b1:b10,5)

where
a1 is the value sought
B1:B10 is the column you're looking in
5 is the absolute column you want returned (in this case 5="E")

You can add a false parameter, and then the column parameter becomes the offset from the column you're looking in, e.g.
=myvlookup(a1,b1:b10,1,false)

in which case it returns 1 column right of B1:B10, ie column C.

Thomas
0
 

Author Closing Comment

by:SeeKnowledge
ID: 35086591
Thanks for the tip, followed the link the response from Brad was excellent referring to the following link
 http://www.cpearson.com/excel/lookups.htm#LeftLookup
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Office 2016 Excel Issue 4 25
Fixing a embedded format 7 29
Excel Save As Status Box will not go away 6 16
Error in formula not increasing value 2 0
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now