Solved

# Value result from Vlookup

Posted on 2013-11-13
395 Views
Hi Guys, can anyone help me resolve why the Vlookup is failing in the T column in my spreadsheet and I get a #VALUE# result? It uses a lookup on Column B from a concatenation of cells.
DummyRec4.xlsx
0
Question by:Justincut
• 5
• 3

LVL 23

Accepted Solution

NBVC earned 500 total points
It is because the contents of the cell B304 is greater than 255 characters, which VLOOKUP, MATCH, SUMIF, COUNTIF don't work with.

You can try perhaps SUMPRODUCT.. but you need to limit the range sizes to min required.

e.g

=SUMPRODUCT(--(Journals!\$B\$1:\$B\$1000=B305),Journals!\$O\$1:\$O\$1000)
0

Author Comment

What about creating my own Vlookup via a Function inserted into myWorksheet? Would that work? What code would I need?
0

LVL 23

Expert Comment

Not sure if a UDF would be more efficient... you can try:

=INDEX(Journals!\$B\$1:\$B\$1000,MATCH(TRUE,INDEX(Journals!\$B\$1:\$B\$1000=B304,0),0))

again limiting rows to min needed, perhaps by creating a Dynamic Named Range.
0

Author Comment

Hi,

You need to write your own VLOOKUP that doesn't have this limitation.

ALT+F11 to open VB editor, right click 'ThisWorkbook and insert module and paste the code below in. Close VB editor and back on the worksheet call with the formula

=MyVlookup(A1,Sheet5!A1:B100,2)

Where A1 is the lookup value, Sheet5A1:B100 is the lookup range and 2 is the column you want to return.

Function MyVlookup(Lval As Range, c As Range, oset As Long) As Variant
Dim cl As Range
For Each cl In c.Columns(1).Cells
If UCase(Lval) = UCase(cl) Then
MyVlookup = cl.Offset(, oset - 1)
Exit Function
End If
Next
End Function
0

LVL 23

Expert Comment

You would paste the Function macro into your VB editor, by holding ALT and hitting F11, then go to Insert|Module, then paste the function in the window.

Close the editor and in the sheet enter formula like:

=MyVlookup(B304,Journals!B:B,1)

again, the range Journals!B:B is a whole column.  You would need to reduce that for efficiency's sake.

if you want to get column C data, then change to:  =MyVlookup(B304,Journals!B:C,2)
0

Author Comment

Its not working in Range "S5". Any ideas why?
0

LVL 23

Expert Comment

Can you clarify what you mean?  What exact formula are you using and what is expected?
0

LVL 80

Expert Comment

You might consider the following alternative to your VLOOKUP in cell T304:
=IFERROR(VLOOKUP(\$B304,Journals!\$B:\$Q,15,FALSE),IFERROR(LOOKUP(2,1/(LEFT(\$B304,255)=LEFT(Journals!\$B:\$B,255)),Journals!P:P),0))

Note that IFERROR requires Excel 2007 or later.

The first IFERROR uses the VLOOKUP formula that was initially in the cell. It will be faster than an array formula if the concatenation is less than 255 characters.

If the VLOOKUP fails, the next IFERROR uses LOOKUP to return the last match for the first 255 characters in B304 matching a value in worksheet Journals column B. If a match is found, then return a value from Journals column P on that same row.

If the LOOKUP also fails, then return 0.
0

LVL 23

Expert Comment

0

## Featured Post

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…