Microsoft Knowledge Base Email Alertz

The VLOOKUP and HLOOKUP functions contain an argument called range_lookup that allows you to find an exact match to your lookup value without sorting the lookup table.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 181213 - Last Review: September 18, 2011 - Revision: 5.0

How to Use VLOOKUP or HLOOKUP to find an exact match

This article was previously published under Q181213

On This Page

SUMMARY

The VLOOKUP and HLOOKUP functions contain an argument called range_lookup that allows you to find an exact match to your lookup value without sorting the lookup table.

Note It is not necessary to sort the lookup table if you use the range_lookup argument correctly.

MORE INFORMATION

The syntax of these functions are defined as follows.

VLOOKUP Function

   =VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
				
where:
   Argument     Definition of argument
   ---------------------------------------------------------------------

   lookup_value The value to be found in the first column of the array.

   table_array  The table of information in which data is looked up.

   col_index    The column number in the table_array for which the
                matching value should be returned.

   range_lookup It is a logical value that specifies whether
                you want 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 the lookup_value is
                returned. If FALSE, VLOOKUP finds an exact match. If an
                exact match is not found, the #N/A error value is returned.
				
Note If range_lookup is TRUE or omitted (for an approximate match), the values in the first column of table_array must be sorted in ascending order. If range_lookup is FALSE (for an exact match), the table_array does not need to be sorted.

Example That Uses FALSE as the Range_lookup Argument

The following list contains some fruits and their respective colors. Notice that the first column is not sorted:
   A1: Fruit    B1: Color  
   A2: Kiwi     B2: Green 
   A3: Banana   B3: Yellow 
   A4: Grape    B4: Purple  
   A5: Apple    B5: Red   
				
The following formula finds the color (Red) that corresponds to the fruit Apple. You can type the formula in any cell on the worksheet:
=VLOOKUP("Apple",A2:B5,2,FALSE)
				
Notice that if you change the range_lookup argument to TRUE, Excel returns the #N/A error, because the first column is not sorted.

HLOOKUP Function

=HLOOKUP(lookup_value,table_array,row_index_num,range_lookup)
				
where:
   Argument     Definition of argument
   ---------------------------------------------------------------------

   lookup_value The value to be found in the first column of the array.

   table_array  The table of information in which data is looked up.

   row_index    The row number in the table_array for which the
                matching value should be returned.

   range_lookup It is a logical value that specifies whether
                you want 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 the lookup_value is
                returned. If FALSE, VLOOKUP finds an exact match.
                If an exact match is not found, the #N/A error value is
                returned.
				
Note If range_lookup is TRUE or omitted (for an approximate match), the values in the first row of table_array must be sorted in ascending order. If range_lookup is FALSE (for an exact match), the table_array does not need to be sorted.

Example That Uses FALSE as the Range_lookup Argument

The following list contains some fruits and their respective colors. Notice that the first column is not sorted:
   A1: Fruit    B1: Color
   A2: Kiwi     B2: Green
   A3: Banana   B3: Yellow
   A4: Grape    B4: Purple
   A5: Apple    B5: Red
				
The following formula finds the Color column, and returns the third item (-1) for the heading Yellow. You can type the formula in any cell on the worksheet:
=HLOOKUP("Color",A1:B5,3,FALSE)
				
Notice that if you change the range_lookup argument to TRUE, Excel returns the #N/A error, because the first column is not sorted.

REFERENCES

For additional information about how to use LOOKUP functions in Microsoft Excel, click the article numbers below to view the articles in the Microsoft Knowledge Base:
181212  (http://kbalertz.com/Feedback.aspx?kbNumber=181212/EN-US/ ) XL: Performing a Lookup with Unsorted Data in Excel
214264  (http://kbalertz.com/Feedback.aspx?kbNumber=214264/EN-US/ ) XL: How to Perform a Case-Sensitive Lookup
214069  (http://kbalertz.com/Feedback.aspx?kbNumber=214069/EN-US/ ) XL: How to Return the First or Last Match in an Array
181201  (http://kbalertz.com/Feedback.aspx?kbNumber=181201/EN-US/ ) XL: HLOOKUP, VLOOKUP, LOOKUP Return Incorrect Values
213476  (http://kbalertz.com/Feedback.aspx?kbNumber=213476/EN-US/ ) XL: Unexpected Results with Mixed Text and Numbers in Lookup Table
280094  (http://kbalertz.com/Feedback.aspx?kbNumber=280094/EN-US/ ) XL: Sample User-Defined Function to Hide Formula Errors
For more information about the HLOOKUP function, click Microsoft Excel Help on the Help menu, type HLOOKUP worksheet function in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about the VLOOKUP function, click Microsoft Excel Help on the Help menu, type VLOOKUP worksheet function in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

APPLIES TO
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Excel 97 Standard Edition
  • Microsoft Office Excel 2003
  • Microsoft Excel 2010
  • Microsoft Office Excel 2007
Keywords: 
kbhowto KB181213
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Mary Report As Irrelevant  
Written: 10/6/2007 10:42 AM
This solved my problem. Vlookup wasn't working in Excel VBA after I added a new item to the end of a table and resorted the table. I added False to all my vlookup statements, and now everything works perfectly.