Professional Documents
Culture Documents
Dr. A. Okullo 2
Looks for a match between lookup_value and
values in the leftmost Column of
table_array and returns the value in a
specified column in the row in which the match
was found.
Where:
Lookup_value is the value to be found in the
first column of the array. Lookup_value can be a
value, a reference, or a text string.
Table_array is the table of information in
which data is looked up. Use a reference to a
range or a range name.
Dr. A. Okullo 3
Col_index_num is the column number
in table_array from which the matching
value should be obtained. For example,
a col_index_num of 2 means the match
value should be obtained form the
second column in table_array; a
col_index_num of 3 means the match
value should be obtained from the third
column in table_array, etc
Dr. A. Okullo 4
Range_lookup is a logical value that
specifies whether you want VLOOKUP to
find an exact match or an
approximate match. If TRUE or
omitted, an approximate match is
returned. In other words, if an exact
match is not found, the next largest value
that is less than lookup_value is returned.
If FALSE, VLOOKUP will find an exact
match. If one is not found, the error
value #N/A is returned.
Dr. A. Okullo 5
If range_lookup is TRUE, the values in the first column
of table_array must be sorted in ascending order:
e.g. -2, -1, 0, 1, 2, or A-Z, FALSE, TRUE; otherwise
VLOOKUP may not give the correct value. If
range_lookup is FALSE, table_array does not need to be
sorted.
If VLOOKUP can't find lookup_value, and range_lookup
is TRUE, it uses the largest value that is less than or
equal to lookup_value.
If lookup_value is smaller than the smallest value in the
first column of table_array, VLOOKUP returns the #N/A
error value.
If VLOOKUP can't find lookup_value, and range_lookup
is FALSE, VLOOKUP returns the #N/A value.
Lets try vlookup on the worksheet data given below:
Dr. A. Okullo 6
A B C
1 Density Viscosity Temperature
2 0.457 3.55 500
3 0.525 3.25 400
4 0.616 2.93 300
1 doesnt exist,
next highest 5 0.675 2.75 250
value less than 2.57 200
6 0.746
or equal to 1 is
picked. 7 0.835 2.38 150
8 0.946 2.17 100
9 1.09 1.95 50
10 1.29 1.71 0
Dr. A. Okullo 7
=VLOOKUP(1,A2:C10,2): Looks up 1 in
column A, and returns the value from column B
in the same row (2.17).
=VLOOKUP(1,A2:C10,3,TRUE) Looks up
1 in column A, and returns the value from
column C in the same row (100).
=VLOOKUP(2,A2:C10,2,TRUE) Looks up
2 in column A, and returns the value from
column B in the same row (1.71)
=VLOOKUP(0.525,A2:C10,3,FALSE) Looks
up 0.525 in column A, and returns the value
from column C (400).
Dr. A. Okullo 8
Exercises using Vlookup
Dr. A. Okullo 14
Lets look at how these two functions work.
In a table of production figures for
phosphoric acid, it is desired to find the
month with the highest production. We can
use the Excels Max function to return the
maximum value (83119).
Now to return the month of the maximum,
we can use MATCH to find the position of
the maximum value.
To get the maximum value, click cell B14
and type: =MAX(B2:B13) and enter. Now
use the Match and Index.
Dr. A. Okullo 15
Syntax:
Match(lookup_value,lookup
array,match_type_num)
If match_type_num = 0 it returns the
position of the first value = lookup_value.
For example,
Match(83119,A2:A13,0) returns 4, the
position of 83119.
Dr. A. Okullo 16
Secondly use INDEX to return the
value in the same position in the
array of months. INDEX(A2:A13,4)
returns 83119.
Dr. A. Okullo 17
Month Production
Jan 76212
Feb 15379
Mar 62220
Apr 83119
May 33872
Jun 80881
Jul 54263
Aug 35427
Sep 50361
Oct 71600
Nov 133
Dec 22477
Dr. A. Okullo 18
We can now use Ethylene Glycol Table 1 for interpolation
Position:
Match(Lookup_value,known_xs,1).
Now use Index to locate the values in
positions x0, x1, y0 y1 in the table of
data where we want to interpolate. A (x) B (y)
Lookup value =33.3%
Index(x_values,A2) 1 33.3
Index(x_values,A2+1)
2 33 (x0) 2.9
Index(y_values,B2)
Index(y_values,B2+1) (y0)
B=B2+(A1-A2)*(B3-B2)/A3-A2) or 3 34 (x1) 1.4(y1)
y = y0+(x1-x2)*(y1-y0)/x1-x0
Dr. A. Okullo 19
We can now create a custom function in Visual
Basic Application to interpolate and get the y
value corresponding to x value (33.3%)
Dr. A. Okullo 20
After creating your custom function, use it on the
worksheet table just like you would use any in-built
Excel function to do the interpolation. For example,
you would type:
InterpL(lookup_value,known_xs,known_ys) or:
InterpL(33.3,A3:A26,B3:B26)
Check your result and compare with what you got
using the Trend function.
Dr. A. Okullo 21