# Thread: Best way to match a cell value on worksheet

1. ## Best way to match a cell value on worksheet

Hello-I am trying to do a vlookup formula but I an not getting the result I want. The reason I think is that some of the cells in the array table are in text format. I have an error that I can pick that will make this numbers into numbers, however, I can't do this because this won't match the value I am looking up. My formula is this =vlookup(b2,'c:\data\test\Invoice\[log.xls]sheet1'\$d1:\$G\$1500,3). Would a match or an index formula work or is there a way for th lookup to look for values and text too. Any help would be greatly appreciated. Thank you.

2. If B2 is a real number and column 1 of your range contains real numbers, with some represented as text, this ARRAY formula should work:

=INDEX(sheet1!\$F1:\$F\$1500,match(B2,1*sheet1!\$D1:\$D \$1500,0))

(conform with: ALT+CTRL+Enter)

3. Try this:
Code:
`=IF(ISNUMBER(match(B2,'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$d\$1500)),VLOOKUP(B2,'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$G\$1500,3),VLOOKUP(B2&"",'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$G\$1500,3))`
If it finds a match it does the lookup, if not it tries a text version...
Steve
PS this is an approximate match, so the routine expects the series to be sorted and if it is not it can yield odd results...
The exact match version is:
Code:
`=IF(ISNUMBER(match(B2,'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$d\$1500,0)),VLOOKUP(B2,'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$G\$1500,3,0),VLOOKUP(B2&"",'c:\data\test\Invoice\[log.xls]sheet1'!\$D1:\$G\$1500,3,0))`

4. Steve, you tend not to like array formulas. Why? Are they inefficient? Is it better to do an IF test first and make the decision after that?

5. I couldn't get either formula to work. There is an arrow down within the cell that gives me the options to convert text to number, correct error, ignore error, etc.

Kweaver: Do you need to specify the file path and worksheet name from where to look at the information in the index formula?

sdckapr: I get an N/A with the formula you provided.

Thank you both for your help.

6. kweaver:
I uise arrays when needed. When not needed, I do not use them. They can be inefficient if there are multiple ones. If you use 1 array for a range of cells, the workbook can be problematic in the future as inserting a deleting rows can become an issue as you can't easily change the array.

Seba:
Could you attach an example file, demonstrating the issue. An #NA error for both tests suggests to me that the list is not sorted ...

Steve

7. Seba -- yes, you need to put the full path in my array formula. I just didn't type it.

8. sdckapr-You are right the list is not sorted and unfortunately I can't sort it because we track invoice base on the date they come in and not by invoice number.

Kweaver-I will try it again and see if that works. Quick question-Can I make the array formula include empty rows. This are needed since I will be providing the formula to staff to copy and paste.

9. If not sorted, the partial match system does not work. The exact match should work however. But if a match is not found you will get an #NA error...
The exact match starts testing at the start and goes one-by-one through the list. The partial match presumes there is a sort order so can jump around the list and not have to look at all for more efficient lookups.

Steve

10. Thanks sdckapr. The formula works.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•