VLOOKUP for multiple entries - excel

I have a few columns in a sheet. First column being first names and the fifth being their respective age. If I want to search the age column for a particular age say '12' and return their corresponding first names in a separate sheet, what should i do? I tried VLOOKUP but I could not figure out the logic. Can someone help me out?Thank you.

Unfortunately VLOOKUP will not work in this situation,as the Vlookup function cannot reference details on left side, however you can use a combination of INDEX and MATCH functions thou. Lets say you have following table
A B
mark 11
john 23
Selly 30
Youbaraj 45
and you want to get the value of A based on the value of B, you can use something like
=INDEX(A1:A20,MATCH(1,B1:B20,0))
You can use index and match to do HLOOKUP and VLOOKUP looking into any column and getting values of any side.
You can use an Index and Double match .. to get answers from a column by entering its name.
Example:
A B C D
1 col1 col2 col3 col4
2 val1 val2 val3 val4
3 val5 val6 val7 val8
Consider in cell C10 ColumnName:
And in cell C11, you enter the name of a column
Now see what would happen with this function
=index(A1:D3,Match(C11,A1:D1,0),Match(val-to-look-for, Column (a,b,c,d),0))
You can dynamically type a name of a column to get that column name's look up value

Vlookup is very easy to use, however the first column must be arranged alphabeticaly before in order for it to work properly. (and usualy i use only the exact match argument).

Related

MS Excel vlookup a cell, get row, get the rightmost column from that row

Similar question seems to be this. However in my case I need an additional step (I think). What I can't get done is combine these two steps.
Let's say the data structure is as below
Col A | Col B | Col C | Col D | Col E |
Row 1 Val1 | Val2 | Val3 |
Row 2 Val4 | Val5 | Val6 |
Row 3 Val7 | Val8 | Val9 | Val10 | Val11
The formula I am looking for should return results as per below scenerios.
1) In a separate cell, If I enter a value (Val4); Do a VLOOKUP for Val4 in Col A (which is in Row 2) and then return the right most value which is Val6 from Col C
2) In a separate cell, If I enter a value (Val7); Do a VLOOKUP for Val7 in Col A (which is in Row 3) and then return the right most value which is Val10 from Col D
Basically the column values may grow to the right. So I need to lookup the first value -> get the row -> get the rightmost value in the same row....
Any help is much appreciated.
EDIT - 1
After the guidance given here, I came halfway to the solution. First thing to mention is that values in a row can grow (In my sample data set it goes up to column D. But it can grow to Column E,F etc... in any row)
Now, let's assume the value I am searching is in H1. I put Val4 in H1 and the formula:
OFFSET(A1,MATCH($H$1,$A:$A,0),2,1,1). //Since I have hard coded 3rd parameter to 2; it'll give me Val6 (the last column in that row)
Here by MATCH($H$1,$A:$A,0) it returns the row. In my example it'll return Row 2 since I am searching for Val4 (In H1)
Now, I should search columns in Row 2 and stop in ColC since its the last value in Row 2.
In the OFFSET function, 3rd parameter looks for the number of columns. So if I can vary that value based on the row; problem is solved. For example; if I search for Val7, in my OFFSET formula, it'll first find Row 3. But now in OFFSET 3rd parameter must 4 (to get the last value - Val11).
As I search the rows using MATCH($H$1,$A:$A,0); if I can pass that row to CountA() problem is solved like:
CountA(MATCH($H$1,$A:$A,0) : MATCH($H$1,$A:$A,0))
This is invalid. So now trying to use INDIRECT() function like:
COUNTA(INDIRECT(MATCH($H$1,$A:$A,0)&":"&MATCH($H$1,$A:$A,0)))
which basically builds row:row as a string and feeds to CountA()
This works on its own, but when I put this to OFFSET() function 3rd parameter, it doesn't work the way it should.
EDIT - 2 (ANSWER)
Got it to work with formula
OFFSET(A1,MATCH($H$1,$A:$A,0)-1,COUNTA(INDIRECT(MATCH($H$1,$A:$A,0)&":"&MATCH($H$1,$A:$A,0)))-1,1,1)
Only issue is when searching for columns in a row, if you have an empty cell it won't search further using COUNTA().... but otherwise it works the way I want
Assume your data housed in A1:D3
Criteria put in A5:A6, (layout similar to JvdV's table)
If your data is text value, formula in B5 copied down :
=LOOKUP("zzz",INDEX($1:$3,SUMPRODUCT(($1:$3=A5)*ROW(A$1:A$3)),0))
If your data is numeric value, formula in B5 copied down :
=LOOKUP(9.9E+307,INDEX($1:$3,SUMPRODUCT(($1:$3=A5)*ROW(A$1:A$3)),0))
If your data is mixed in text+numeric value, formula in B5 copied down :
=INDEX($1:$3,SUMPRODUCT(($1:$3=A5)*ROW(A$1:A$3)),AGGREGATE(14,6,COLUMN($1:$1)/(INDEX($1:$3,SUMPRODUCT(($1:$3=A5)*ROW(A$1:A$3)),0)<>""),1))
Got it to work with formula
OFFSET(A1,MATCH($H$1,$A:$A,0)-1,COUNTA(INDIRECT(MATCH($H$1,$A:$A,0)&":"&MATCH($H$1,$A:$A,0)))-1,1,1)
Only issue is when searching for columns in a row, if you have an empty cell it won't search further using COUNTA().... but otherwise it works the way I want

Finding and obtaining the difference between two columns

I have two columns. Each column has tens of thousands of values. I need to find the difference between them and print the difference in some cells. I read similar questions, but they are not enough for my question, highlighting the different cells is not enogh for me because it would be very tiring to look at tens of thousands of cell by searching highlighted cells. Thus, i need to obtain the values.
Example:
Column1 Column2
John Jennifer
Mary Washington
Joe John
Michael Texas
Houston Newyork
Texas Mary
Values existing in col1 but not col2 : Joe, Michael, Houston
Values existing in col1 but not col2 : Jennifer, Washington, New York
Algorithmically, i need to check each row of column1 whether it exists in Column2, if the row does not exist in Column2, the value is taken.
Similarly, i need to check each row of column2 whether it exists in Column1, if the row does not exist in Column1, the value is taken.
Thanks
Old: If this is a once-off i'd make a backup then mark the area of the two columns and "remove duplicates" which is a button on the DATA command bar.
You would be left with unique records only, which is what I understand you want.
Edit: If you want to completely remove duplicate values then: Assuming that col1 is "A" and col2 is "B" then this formula only shows the record if it is in A but not in B. You can make a similar one for B not in A. In my example I made two columns C, D for the unique values. Then filter the list on these being "not nothing", and you have a set of unique records.
Current formula is for A2 cell - in my example placed in C2.
=IF(ISERROR(MATCH(A2;B:B;0));A2;"")

How to fill in a cell with text based on a value

I want to fill in one cell with text based on another cell that has a number. So for example if A1 reads 2 I want B1 to read Correct.
In my case I have multiple possible criteria, B1 = Correct is just ONE example.
Will this be a conditional format formula involving an IF function or vlookup possibly?
Basically what I'm looking to do is IF A1 = 2, than B1 = Text
Thanks in advance for an answer to this
Use a VLOOKUP formula
to do this you need a table of key and value
for example
in the range d1:E6 you have the lookup table.
Lookup LookupValue
1 May be correct
2 Don't know
3 It depends
4 probably correct
5 My wife says it is correct
In the range a1:c7 you have your data
col1 col2 col3
kjkjk 2 Don't know
klkl 2 Don't know
jkljkjk 1 May be correct
kjukjkjk 4 probably correct
lklklkl 5 My wife says it is correct
lklklkl 3 It depends
in col3 you use the VLOOKUP
as =VLOOKUP(B2, MyLookupTable, 2)
Note that I named the d1:e6 range as MyLookupTable
THis is what it looks like

Searching 2D Excel array for a value, returning the value of the adjacent cell

I've been scouring this website throughout my last 2 programming classes, and decided it was worth joining this fabulous community!
In a nutshell, I want to create an "invoice maker", which allows one to first select a category via a dropdown box in A1, then an item within that category with a dropdown in B1. Excel would then autofill the price in the next column C1.
Essentially 2 (not sure what to call it: cascading, nested, dependent) dropdown boxes that when both filled, return a price. For example:
A B C
1 Category Item [Price]
Both dropdowns use Data Validation referring to a Defined Name, which is based on an array in sheet "Database". This sheet is formatted like so:
category1 price category2 price category3 price category4 price ...
item1 $xx item1 $xx item1 $xx item1 $xx
item2 $xx item2 $xx item2 $xx item2 $xx
I used this column arrangement mainly because it allows for each category to be expanded indefinitely. If you see a simpler way, let me know!
Essentially, to print the price in C1, my objective is to find the item name in the 2D Excel database, and return the cell immediately to the right of it. Ideally the formula in C1 would use cell A1 to determine which category to search, and search this column for the corresponding item name in B1. Then, it would +1 offset that to the right, thereby referring to the price.
As far as formulas, I have some rough pseudocode, but I'm confused between VLOOKUP, OFFSET, MATCH, and INDEX. Basically:
=INDEX( "defined name of my entire database" , MATCH( B1, **column corresponding to chosen component** , 0 ) + 1 , MATCH( A1 , components , 0 ) )
The way I see it, the INDEX would return the value of row+1 item, in a given column. The first MATCH would find the row in which the item is found, and the second MATCH would determine the column that category is found in.
Now my question is, how do I make the first MATCH search ONLY the column which corresponds to the right category?
Honestly I have no idea if my pseudocode is correct. I translated it to Formula, and it simply returns #N/A in the cell.
Many thanks for any help!!!
I would try the following approach:
Take the first column of the database sheet and offset it so many columns to right how the searched category is offset from the left. Then we have the price column of this category because we have offset it 1 column if it matched the first categrory, 3 if it matched the second category and so on.
From this column indicate the value from the row which is the same as the row in the found offset-1 column (the category column) which matches the searched item name.

MS Excel wildcard lookup

I have a lookup table in Excel with ColA and ColB :
ColA ColB ColC
va 1 value1
ColC is the actual value table
I need to do a wildcard lookup with lookup_value = "value1"
I need to perform an operation that if the value of ColC matches the characters in ColA then it should return me ColB value, i.e. 1
I want to use wildcards in the lookup function to achieve this result.
Any help will be appreciated!
Thanks
You can use wildcards with VLOOKUP. You'll have to rearrange your table so that the lookup column is the first column, but other than that it should work. I put:
abc 1
def 2
ghi 3
jkl 4
into a range named "table"
Then:
g*
g?i
?kl
into F2:F4
Now, in G2:G4, I put this formula:
=VLOOKUP(F2,table,2,FALSE)
and it correctly found 3 in cells G2 & G3, and 4 in cell G4.
The asterisk means zero or more characters; the question mark means exactly one character.
This works as a wild card with text strings:
=vlookup("*"&REF&"*",lookup range, column, false)
It turns a number into text to do a wild card on a number. Stars should go between the quotations but they are not showing up.
You can do it this way:
=VLOOKUP(LOOKUP("value1",ColC:ColC,ColC:ColC), lookuprange, COLUMN(ColA) + 1, TRUE)
Of course you can simplify this with your domain knowledge.
This method allows you to use your lookup table as is.

Resources