Problems with Vlookup

HI Guys, I have a Vlookup that does not work as there is a 256 limit in Excel.Would the formula work if I did Left(Range, 255) on the cell the vlookup is on? Some of the cells I vlookup are 400 characters and I get a "#VALUE" error message as a result,
Who is Participating?
VLOOKUP requires that the search value (first parameter) and lookup column (in lookup table) be less than 255 characters in length. By using LEFT, you truncate the strings to satisfy that constraint.

If you copy the Rec worksheet, you will need to point your VLOOKUP formulas to that worksheet. I suggest instead copying the data from the Rec worksheet and pasting it in a "Previous Day" worksheet in the VLOOKUP workbook. In doing so, you won't need to change any of your formulas. They will all be set up to point to the Previous Day worksheet, and don't need to be changed for the new data.
No. Both the lookup parameter and the first column of the lookup table need to be less than 256 characters. This is a "feature" of Microsoft Excel.

If you are doing a concatenation of lookup parameters so you can use VLOOKUP on what would otherwise be a multi-criteria lookup, you can use an array formula instead.
Here is a LOOKUP formula that does the same type of thing that a concatenated lookup parameter would do with VLOOKUP. It gets around the 256 character limit because each criteria is less than 256 characters. It does not need to be array-entered (like SUMPRODUCT) although it is an array formula in essence. It returns a value from column C where column A equals "a" and column B equals 4.

Though the formula only shows two criteria, you can put as many criteria in the denominator of the second parameter as you like. Just surround each Boolean expression by parentheses, then multiply them all together.

To help understand the formula, if there is a match, the second parameter will equal 1. If there is no match, the second parameter will return an error value. Since LOOKUP is searching for a number, it will ignore text and error values. It therefore finds the row in which all criteria are satisfied, and returns a value from a different column in that row.

LOOKUP was originally intended for bracket pricing (approximate) lookups. If you read Microsoft's documentation for the function, you may draw the misleading conclusion that the second parameter has to be sorted in ascending order. For the suggested formula, however, 2 is larger than any possible value returned by the second parameter, so the sorting requirement is moot.

Note that LOOKUP will return the last match if more than one exists.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

JustincutAuthor Commented:
Can you tell me how to overcome the VALUE error message in Range ("AD5") of this attachment? Its baiscally looking up the same tab but the Previous days. We roll it on a daily basis.
VLOOKUP will produce a #VALUE! error if either the lookup parameter or the first column of the lookup table has more than 255 characters. To overcome this, you must not use VLOOKUP.

Each of the VLOOKUP calls in the formula of cell AD5 can be rewritten as a LOOKUP formula like:
=LOOKUP(2,1/(('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!A$1:A$1000=A5)*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!E$1:E$1000=E5))*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!F$1:F$1000=F5))*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!G$1:G$1000=G5))*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!H$1:H$1000=H5))*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!I$1:I$1000=I5))*('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!J$1:J$1000=J5)),INDEX('[Murex BS rec breaks - 111113KMH.xlsx]Rec'!B$1:AL$1000,,AD$1))

You didn't post workbook Murex BS rec breaks - 111113 KMH.xlsx so I guessed how column B in the Rec worksheet of that workbook is determined.

Given the length of the above formula, you may want to use a UDF instead with formula like:
=LookupAlt('[Murex BS rec breaks - 111113 KMH.xlsx]Rec'!$B$1:$AL$1000,AD$1,1,A5,5,E5,6,F5,7,G5,8,H5,9,I5,10,J5)
You can use LookupAlt just like the VLOOKUP in your AD5 formula. Just correct the column assignments.

Do not use LookupAlt on entire columns! Doing so will give excruciatingly slow recalc times.

'Code goes in regular module sheet
Function LookupAlt(LookupTable As Range, ResultColumn As Long, CritCol1 As Long, Crit1, CritCol2 As Long, Crit2, _
                CritCol3 As Long, Crit3, CritCol4 As Long, Crit4, CritCol5 As Long, Crit5, CritCol6 As Long, Crit6, _
                CritCol7 As Long, Crit7)
Dim rg1 As Range, rg2 As Range, rg3 As Range, rg4 As Range, rg5 As Range, rg6 As Range, rg7 As Range, rgResults As Range
Set rg1 = LookupTable.Columns(CritCol1)
Set rg2 = LookupTable.Columns(CritCol2)
Set rg3 = LookupTable.Columns(CritCol3)
Set rg4 = LookupTable.Columns(CritCol4)
Set rg5 = LookupTable.Columns(CritCol5)
Set rg6 = LookupTable.Columns(CritCol6)
Set rg7 = LookupTable.Columns(CritCol7)
Set rgResults = LookupTable.Columns(ResultColumn)
LookupAlt = Application.Lookup(2, 1 / ((rg1 = Crit1) * (rg2 = Crit2) * (rg3 = Crit3) * (rg4 = Crit4) * (rg5 = Crit5) * (rg6 = Crit6) * (rg7 = Crit7)), rgResults)
End Function

Open in new window

JustincutAuthor Commented:
Hi Guys, can you cut and paste the Rec tab onto the same spreadsheet and then do I Vlookup. What I usually do is roll the Rec on a Daily Basis and do a Vlookup to the Previous business Day. I don't know why but when I put Left(Concatenate(A5, etc), 250) in column B, the Vlookup seems to work.Any ideas why?
JustincutAuthor Commented:
If you look at my attachment I have put a LEFT formula in the B column and all the VALUEs from the AD column have disappeared. How come?
Column AD appears to have values in all the cells. Which ones did you think were missing in the workbook you attached?
JustincutAuthor Commented:
I mean all the "#VALUE#" error messages have disappeared. According to you, the LEFT (Range, 250) Formula should not be working.
The VLOOKUP(LEFT(Range,255),lookup table,...) formula is in fact failing in all 30 cases where column B length would otherwise exceed 255 characters without the LEFT.

Column AD formulas are working despite this failure because the maximum length in column C is 41 characters. So the alternative VLOOKUP formulas are all working.

I broke the formula in cell AD5 up into 5 lines for ease of explanation:
=IF(ISNA(VLOOKUP($B5,'Prev Day'!$B:$AL,AD$1,FALSE)),
                     IF(ISNA(VLOOKUP($C5,'Prev Day'!$C:$AL,AD$1-1,FALSE)),"NEW",
                                       VLOOKUP($C5,'Prev Day'!$C:$AL,AD$1-1,FALSE))),
         VLOOKUP($B5,'Prev Day'!$B:$AL,AD$1,FALSE))

Line 1 VLOOKUP returns #N/A! error value because column B on worksheet Prev Day hasn't been truncated to 255 characters. Even if there were a match for the first 255 characters, the VLOOKUP on line 1 won't find it.

The line 2 test for J5 being blank fails, so control passes to the IF(ISNA(VLOOKUP... on line 3. This VLOOKUP works because C5 is both short and always found. As a result, the formula returns the value from the VLOOKUP on line 4.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.