VLOOKUP by Combining 2 Columns to Form a Unique Key - vba

For the following table,
I want to look up the value in col C. Since the values in col A and col B are not unique, VLOOKUP fails. For example, VLOOKUP(1,table,3) returns 5 and never 1.
However, the combinations of cols A & B are unique. For example, 1blah = 5, while 1foo = 1.
How can I use the combination of cols A & B as a unique key to return the corresponding value in col C?
I'm not sure if this should be implemented with worksheet functions or a custom VBA function. I tried using CONCATENATE to generate the unique key, but this did not work because this results in combinations of numbers and strings.

You can use an array formula:
=INDEX($C$1:$C$7,MATCH("1foo",$A$1:$A$7 & $B$1:$B$7,0))
just select in example D1, enter formula in formula bar and press CTRL+SHIFT+ENTER to evaluate it

The way I usually do it is by concatenating the values separated by a pipe character (|). See the formula in the screenshot below.
Then you can vlookup using the concatenated key.
=VLOOKUP("1|foo",$C$1:$D$7,2,FALSE)

You can use VLOOKUP if your lookup value is a concatenation of your two or more key fields (A2&B2). Then, add a first sorted column in your LUT sheet with the array that is the concatenation of the same key fields. Viola.

Related

VLOOKUP to return multiple matches

I want to ask if there's a way/formula/vba to return multiple values when using vlookup? For example, I vlookup a data and when that data has multiple values to return, it will return the other values. Thanks.
For something as generic as this, just use Google.
Step #1) www.google.com
Step #2) get your answer in less time than it takes you to post here.
Return MULTIPLE corresponding values for ONE Lookup Value
The Excel VLOOKUP Function searches for a value (ie. Lookup_value) in the first column of a table array and returns a value in the same row from another column in the table array. In case of multiple occurrences of the Lookup value, the function searches the first occurrence of the Lookup value, and returns the corresponding value in the same row from another column.
In case you want to return multiple corresponding values, for the one Lookup value which has multiple occurrences, we show how it can be done using INDEX, SMALL, IF & ROW excel functions, as follows.
Consider the table array ("A2:B8"), in which you want to lookup the value "Apples" in column A which has multiple occurrences, and return all corresponding values in column B.
Enter the lookup value "Apples" in cell A11. In cell B11, enter below formula, as an array formula (CTRL+SHIFT+ENTER), and copy it downward in the same column B, in 7 rows (ie. number of times as the number of records in the table array "A2:B8". Multiple corresponding values (of the lookup value "Apples") will get copied vertically, starting from cell B11 till B17. Refer Table 1.
=INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1)))
http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=119:vlookup-multiple-values-return-multiple-corresponding-values-for-one-lookup-value&catid=77&Itemid=473

How to combine INDEX, IFERROR and VLOOKUP formulas

I would like to Index a columns info, run a vlookup of a particular text(s) and then perform an if error to ignore things not like the "lookup value". I have data in column V called "Biscuits" amongst other items of different names. "Biscuits" has to be replaced with a different name. But the name change will not be the same for each occurrence. I would like to maintain the original column V's data and Index that particular columns values into another column. Once I have created a "copy" of the original data named column AV, I then need to run a vlookup on column AV. I have a column AW that has manual information of different names inputted in this column. In the "Indexed" Column AV I would like to run vlookup on "Biscuits" ONLY, skipping other entries and replace "Biscuits" with the contents of column AW (all entries in Column AW for name changes are on the same lines as "Biscuits"
Example
Original Column, Indexed Column, Manual input column and final result
=INDEX(V2, ,)-this is the formula I wrote to Index column V, thus creating column AV
=IFERROR(VLOOKUP("Biscuits",V2:AW2,28,FALSE),"")-This is a formula I wrote to look for "Biscuits" and replace it with the contents of column AW
Please help on this.
Thank you!
According to OP It worked!, the formula being:
=IF(AW2="",V2,AW2)
Ie return the contents of V2 if AW2 is empty and the contents of AW2 otherwise. This can be copied down to apply to other rows, with references adjusting automatically. Neither the 'index column' nor any of INDEX, IFERROR or VLOOKUP were required.

Find value in column, based on 2 criteria

I have a file with 3 columns. Column A contains 300,000 rows, with about 200 separate IDs, all duplicated at least 1,000 times. Column B contains the date for each of the rows. Column C contains the values that I need to extract.
Each of the 200 IDs in Col A can have multiple values (e.g. ID 1234 might have dates 1/1/2001, 1/3/2001, 1/2/2015, etc). Similarly, each date on Col B will have multiple IDs (e.g. 1/2/15 might have IDs of 1234, 1874, 1930, 6043, etc).
In a nutshell, I need to check the values in Col A and Col B to find the relevant ID in Col A and the maximum value in Col B, and return the value in the relevant cell in Col C.
I've looked at Index/Match examples, but they don't seem to be suitable. Is there any suggestions on a macro I could run, that would accomplish what is needed.
Use this array formula:
=INDEX($C$1:$C$300000,MATCH(1,IF(($A$1:$A$300000="1234")*($B$1:$B$300000=MAX(IF($A$1:$A$300000="1234",$B$1:$B$300000))),1,0),0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
Change the "1234" to a reference cell with the appropriate ID.
You can accomplish this using array formulas. To start, you can retrieve the maximum date in column B when column A is 1234 using the below formula. Keep in mind that you have to use Ctrl-Shift-Enter when you finish typing an array formula.
{=MAX(IF($A$2:$A$24=1234,$B$2:$B$24))}
Note that you will need to change the ranges to include all of your data, rather than my test data on rows 2-24.
Now that you have a formula to retrieve the max date, you can put that inside an index/match and, again using Ctrl-Shift-Enter, use the below array formula to retrieve the value in column C for a row matching 1234 and the maximum date.
{=INDEX($C$2:$C$24,MATCH(1234&MAX(IF($A$2:$A$24=1234,$B$2:$B$24)),$A$2:$A$24&$B$2:$B$24,0))}

Comparing rows to identify matches and mismatches

I have a sheet with 10000+ rows, but the data came from 2 sources, so duplicates exist for the same combination of unique keys. So let's say that columns A and B are the unique identifier. Columns C to K have data about the item specified by the unique key. I need to check if there is a second occurrence of the unique key combination and if so, are the data in columns C to K in the second occurrence the same as in the first occurrence. If they are the same, then copy the row to sheet 2.
if a1 = a2 and b1 = b2 then check if c1:k1 equals c2:k2 -> copy to sheet 2
I need to create separate lists of matches and mismatches.
Have you tried using vlookup? When you do this in both directions, you know what the differences are between the two lists. When doing this, make sure that things like spaces are exactly the same. Try using trim on both lists first to remove extra spaces.

Excel 2007 - Compare 2 columns, find matching values

I have two colums. Column A and Column B which have email addresses. Column A has about 3000 rows, Column B has about 1800. Is there anyway to compare the two columns, and find any fields that match...
And if so, how to either highlight or flag them as a match... or shit, for even simplicitys sake, just give me a count of how many matches were found...
Should i try a macro? Or is there a forumula that will help with this?
You could fill the C Column with variations on the following formula:
=IF(ISERROR(MATCH(A1,$B:$B,0)),"",A1)
Then C would only contain values that were in A and C.
=VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) will solve this issue.
This will search for a value in the first column to the left and return the value in the same row from a specific column.
VLOOKUP deosnt work for String literals