On 2002-04-03 05:35, Nobby wrote:
Thanks for that, but it raises a couple of issues (ie exposing my ignorance again!)
Firstly, the formula is trying to match the text entry in H5 with the list of text in B25:B37 and then return the code contained in the corresponding cell in column A. I thought that the 1 in the VLOOKUP formula selected the column from which to return data? Have I got this wrong?
Secondly, using your suggestion of adding a 0 for an exact match now returns a blank. It can't be a typo causing it to fail because the text in H5 is created from a data validation list.
Any ideas where I'm going wrong?
Cheers
Nobby
Yes,
The help file for VLOOKUP is:
Searches for a value in the
leftmost column of a table, and then returns a value in the same row from a column you specify in the table. Use VLOOKUP instead of HLOOKUP when your comparison values are located in a column to the left of the data you want to find.
Syntax
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
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, such as Database or List.
· If range_lookup is TRUE, the values in the first column of table_array must be placed in ascending order: ..., -2, -1, 0, 1, 2, ..., 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.
· You can put the values in ascending order by choosing the Sort command from the Data menu and selecting Ascending.
· The values in the first column of table_array can be text, numbers, or logical values.
· Uppercase and lowercase text are equivalent.
Col_index_num is the column number in table_array from which the matching value must be returned. A col_index_num of 1 returns the value in the first column in table_array; a col_index_num of 2 returns the value in the second column in table_array, and so on. If col_index_num is less than 1, VLOOKUP returns the #VALUE! error value; if col_index_num is greater than the number of columns in table_array, VLOOKUP returns the #REF! error value.
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.
Remarks
· 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.
take note of the bold.
Also you can't use a negative value for the returning Column.
In this case you should INDEX and MATCH
so, use:
=INDEX(A25:B37,MATCH(H5,B25:B37,0),1)
If you care to look at the help files on these it'll let you know how they work and similarities between this and VLOOKUP. (You've got your homework, so be warned, you may be tested).