Вы находитесь на странице: 1из 2

Learn Excel 2007 Expert Skills with The Smart Method

Lesson 3-22: Use a VLOOKUP


function for an exact lookup
Considerthefollowingworksheet:

Theretailerhascreatedastockcodetosavetimewhencreatinginvoices.
Thecodeismadeupofthefirsttwolettersofthewatchdescription,
alongwiththetwolastnumbersofthedateofmanufacture.
Whenprovidedwithastockcode,theVLOOKUPfunctioncanscanallof
thecodesincolumnAuntilamatchisfoundandthenreturnavalue
fromthesamerowforanyoftheothercolumns.
Inthislesson,wewillcreateaVLOOKUPthatwillautomaticallyreturn
theDescriptionofanywatch,intocolumnBwhentheuserentersastock
codeintocolumnA.

Open Invoice-1 from your sample files folder.

Convert the range A5:G15 on the Stock worksheet into a


table named Stock.
Thiswascoveredin:Lesson18:Convertarangeintoatableandadda
totalrowandLesson114:Nameatableandcreateanautomatic
structuredtablereference.
WhenworkingwiththeVLOOKUPfunctioninExcel2007itisbest
practicetouseatablefortheTable_arrayargument(seesidebaron
facingpage).
Usingatablewillmakethedatadynamic.Inotherwords,the
VLOOKUPwillstillworkcorrectlyifyouaddandremoverows
fromtheStocktable.

Invoice-1

140

AutoSize all columns so that each column is wide enough to


display all data.

Insert a VLOOKUP function into cell B6 on the Invoice


worksheet to find the description to match the Code in cell
A6.
1.

ClickincellB6.

2.

Click:FormulasFunctionLibrary
Lookup&ReferenceVLOOKUP.

www.LearnMicrosoftExcel.com

Session Three: Advanced Functions

TheVLOOKUPFunctionArgumentsdialogappears.Itcanbe
seenthattheVLOOKUPfunctionhasthreerequiredarguments
(showninboldface)andoneoptionalargument:

important
It is best practice to
use tables with your
VLOOKUP functions
InthislessonIveshownyou
howtoconstructaVLOOKUP
thatusesatableforthe
Table_arrayargument.

ThisisthecellontheInvoiceworksheetthatprovidesthevalueto
besearchedforinColumnAoftheStockworksheet.Wewantto
lookupthedescriptionforthewatchthathasthecodeCA74.This
iscontainedincellA6.

ThisisbestpracticeinExcel
2007,butitwasntpossiblein
Excel2003asthe(fantastically
useful)tablefeaturewasnt
available.
Inworksheetsconstructed
usingearlierversionsofExcelit
iscommontoseeabsolute
rangereferencesforTable_array
argumentslikethis:

WhenyouseeaRangeName
referenceitlooksthesameasa
tablereference.Thisexample
showstheuseofaRangeName
alsocalledStock:

1.

ItisbestpracticetouseatablefortheTable_arrayargument
(seesidebar).

Add the Col_index_num argument.

Countingfromlefttoright,theCol_index_numargumentisthe
columnthatcontainsthevaluewewanttoreturn.Inthiscase,itis
theDescriptioncolumn,sowewanttoreturncolumn2.

Usersofearlierversionshadto
resorttoacomplexwork
aroundtomaketheirRange
Namesdynamic.Youlllearn
aboutthisworkaroundin:
Lesson46:Createdynamic
formulabasedrangenamesusing
theOFFSETfunction.
Thisinformationisprovidedso
thatyouwillunderstandany
olderExcelworksheetsyou
mayinherit,(orworksheets
thatwerecreatedbyusersthat
haventyetlearnedhowtouse
tables)!

TypeStockintotheTable_arraytextbox.

WhileRangeNameswerebest
practiceinearlierExcel
versions,theyhaveafatalflaw
astheyarenottrulydynamic.

Add the Table_array argument.


Thetablearrayistherange,tableorname(seesidebar)wewill
searchforamatchtothevalueincellA6.VLOOKUPalways
searchestheleftmostcolumnoftherange,tableorname.

Moresophisticatedusersof
earlierExcelversionslearned
howtouseRangeNames.
(YoulllearnallaboutRange
Namesin:SessionFour:Using
NamesandtheFormulaAuditing
Tools).

Add the Lookup_value argument.

Add the Range_lookup argument.


Beginnersoftenoverlookthisvitalargumentbecauseitisoptional.
Ifitisleftblank,VLOOKUPwillreturnaninexactmatch.Later,in
Lesson324:UseaVLOOKUPfunctionforaninexactlookup,wellfind
whythatmightbeuseful,butinthiscasewewantanerrortobe
returnedifthestockcodeisnotfound,soitisvitaltosetthis
argumenttoFALSE.

Click the OK button.


ThedescriptionoftheCartierTankisreturnedtocellB6.

10
2009 The Smart Method Ltd

Save your work as Invoice-2.

141

Вам также может понравиться