3

Using excel 2003, the formula:

=VLOOKUP(D1 ,A1:B135, 2)

fails if the length of D1 exceeds 255 characters (i.e. the list has some text longer then 255 characters, D1 has the same text value, and VLOOKUP returns #VALUE!).

MATCH seems to suffer from the same character limit.

I cannot find any official confirmation of these limits, for example here:

http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx

or here:

http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx?CTT=3

I know that excel has a 255 limit on the length of text used in formulae, but it suggests connate should work (it does not in this case, and I am not using strings in the formula, but referencing another cell).

Can somebody confirm that these limit exist (it is always possible I am doing something else wrong)?

More importantly, does anyone know of a way around them?

Thanks

4

4 Answers 4

3

You can always code your own VLOOKUP... but, as an alternative, you can compute a hash from your lookup value, and use it as a new lookup value.

Collisions may happen, but using a somewhat decent hash algorithm, like MD5, it shouldn't be a problem.

To create a hash function, you may use the ideas from https://stackoverflow.com/questions/125785/password-hash-function-for-excel-vba.

1
2

Write your own lookup in VBA

Here's a start:

Function MyVL(v As Range, r As Range, os As Long) As Variant
    Dim cl As Range

    For Each cl In r.Columns(1).Cells
        If v = cl Then
            MyVL = cl.Offset(0, os - 1)
            Exit Function
        End If
    Next
End Function
1

I was searching for exact matches between 2 reports and ran into this. I concatenated the several different fields of one report and another report into one LONG string and then used Vlookup to identify if every field of 1000 records or so matched between the 2 reports. That's when I ran into the problem.

Because it was a one-time thing and I could break it down into smaller chunks by concatenating less than 255 characters into 3 separate columns, I did that and wrote 3 separate lookups and compared the data in 3 chunks rather than all at once. The major drawback is that I had to re-sort by the lookup table (column) I wanted to run the lookup on for each of the 3 sub groups before running each lookup.

Id call my solution perfectly acceptable for a onetime thing, but if I had to do it more than once, I'd look for something more efficient.

0

An additional consideration is that, if an answer is not found using those first 255 characters, then they aren't needed. So one can nest lookups in an IF() structure (or IFS(), even better with this one) and each successive lookup can be done on a truncated version of the values in the lookup column. Use RIGHT() and for length, subtract 255 from the cell's length.

Nowadays (2021), LET() is available so one can make the successive lengths shorter much more easily.

Of course, there's XLOOKUP() now as well. I do not know its limitations for lookup value string length, but can say for sure it is at least 518 characters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .