Article ID: 200855 - Last Review: September 12, 2006 - Revision: 3.2 XL98: Unexpected Results with Mixed Text and Numbers in Lookup TableThis article was previously published under Q200855 For a Microsoft Excel 97 and later version of this article, see 213476
(http://support.microsoft.com/kb/213476/EN-US/
)
.
For a Microsoft Excel 7.0 and earlier version of this article, see 113261 (http://support.microsoft.com/kb/113261/EN-US/ ) . On This PageSYMPTOMS
After you create a lookup table, you may experience either of the following symptoms:
CAUSE
When you look up a text value, Microsoft Excel looks only at the text values in your table. Similarly, when you look up a numeric value, Microsoft Excel looks only at the numeric values.
WORKAROUNDMethod 1: Include Minimum and Maximum Values for Both Text and NumbersIf you want your lookup table to be split into separate tables for text and numbers (the default), you must include minimum values for both the text and the numeric values in your lookup table.Zero is the lowest positive integer and the blank space character is the lowest printable text character. Method 2: Format All Cells as TextIf you want the table to behave the way it appears after it is sorted by Microsoft Excel, such that it returns the highest numeric value if a text value is looked up, then you must treat your table as text only. The following are two ways to do this:
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. MORE INFORMATION
If the first column (VLOOKUP) or row (HLOOKUP) of your lookup table
contains both text and numeric values, you can use Microsoft Excel to sort
your table in ascending order. In this case, the numeric values will appear
at the beginning of the table and the text values will appear at the end of
the table. Both text and numbers are then sorted as expected.
For example, the following values
A1: 3 A2: 1 A3: c A4: 2 A5: d A6: b A1: 1 A2: 2 A3: 3 A4: b A5: c A6: d It may appear that =VLOOKUP("a",A1:A6,1) should return the value 3, which is the largest value that is less than the lookup value a. However, the formula returns the #N/A error value instead. This behavior also occurs with HLOOKUP(), LOOKUP(), and MATCH() with Match Type arguments of 1 or negative one (-1). The same behavior also holds true if you attempt to look up a numeric value that is less than the first numeric value in your lookup table. Sample Visual Basic Macro Using VLookupMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.REFERENCESFor more information about Lookup Functions, follow these steps:
For additional information about getting help with Visual Basic for Applications, please click the article number below to view the article in the Microsoft Knowledge Base: 163435
(http://support.microsoft.com/kb/163435/EN-US/
)
VBA: Programming Resources for Visual Basic for Applications
| Article Translations
|

Back to the top
