I had to compare some simple lists. I could have used a database, loaded the lists and used sql to do the comparisons. Not in the mood for that, then let's just use Excel.
We have the following two lists in a spreadsheet and we want to know which of the values in column
B exists in column
A:
| |
A |
B |
C |
| 1 |
Fusce |
Vestibulum |
|
| 2 |
mauris |
mattis |
|
| 3 |
nulla |
Fusce |
|
| 4 |
pellentesque |
consequat |
|
| 5 |
iaculis |
libero |
|
| 6 |
aliquam |
eu |
|
| 7 |
eu |
sem |
|
| 8 |
tincidunt |
Nullam |
|
| 9 |
consequat |
iaculis |
|
| 10 |
metus |
elit |
|
After some digging around in the Excel functions, I found
VLOOKUP that does the trick:
| |
A |
B |
C |
| 1 |
Fusce |
Vestibulum
|
=VLOOKUP(B1,$A$1:$A$10,1,FALSE) |
| 2 |
mauris |
mattis |
#N/A |
| 3 |
nulla |
Fusce |
Fusce |
| 4 |
pellentesque |
consequat |
consequat |
| 5 |
iaculis |
libero |
#N/A |
| 6 |
aliquam |
eu |
eu |
| 7 |
eu |
sem |
#N/A |
| 8 |
tincidunt |
Nullam |
#N/A |
| 9 |
consequat |
iaculis |
iaculis |
| 10 |
metus |
elit |
#N/A |
In column
C it prints the search value if it was found, or "#N/A" if not found. This is ok, but we can make it look a bit nicer by adapting the formula a little bit:
| |
A |
B |
C |
| 1 |
Fusce |
Vestibulum
|
=ISNA(VLOOKUP(B1,$A$1:$A$10,1,FALSE)=B1)=FALSE |
| 2 |
mauris |
mattis |
FALSE |
| 3 |
nulla |
Fusce |
TRUE |
| 4 |
pellentesque |
consequat |
TRUE |
| 5 |
iaculis |
libero |
FALSE |
| 6 |
aliquam |
eu |
TRUE |
| 7 |
eu |
sem |
FALSE |
| 8 |
tincidunt |
Nullam |
FALSE |
| 9 |
consequat |
iaculis |
TRUE |
| 10 |
metus |
elit |
FALSE |
Using the updated formula, "TRUE" is printed if the value in column B is the same as the value returned from
VLOOKUP otherwise "#N/A" is returned. This in turn is handled by the
ISNA function, that's return value is then inverted so that the "TRUE" for "#N/A" is displayed as "FALSE" (the value was not found).