Google-sheets – VLOOKUP using cell reference with IMPORTRANGE gives error

formulasgoogle sheetsimportrangevlookup

I can't see what I'm doing wrong with this.

This Doesn't Work

=Vlookup(L2,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1_Le0cMfbHRSgXqhCdzjQrBscFNm6p1sL-DowWdCZ0Fs/edit#gid=1761671943","responses!B2:R8"),4,0)

I get this error:

Did not find value '102' in VLOOKUP evaluation.

Error image

This Does Work

=Vlookup(102,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1_Le0cMfbHRSgXqhCdzjQrBscFNm6p1sL-DowWdCZ0Fs/edit#gid=1761671943","responses!B2:R8"),4,0)

I get the correct value.

Working image

The only difference is the first version (not working) uses a cell reference L2 in the VLOOKUP. The second version (working) uses a static value 102 in the VLOOKUP.

I've tried wrapping in " and ' but neither work.

Can someone please help me fix this so it works with a cell name and explains why my solution isn't working?

enter image description here

Best Answer

VLOOKUP is format sensitive. It neither 'matches' text to number nor number to text, even where on screen the appearance is identical. This is a standard gotcha, though unfortunately not mentioned here. (Another is 'trailing spaces', specially NBSP, which can complicate diagnosis.)

However the data (whether the search_key or part of the range) need not be reformatted for VLOOKUP to work as the 'conversion' may be done 'on the fly'.

For example, converting a text search_key to numeric format can be achieved by prepending -- (the double unary), or by coercion with 1* (multipying by 1) within a formula.

In OP's case this might mean replacing L2 with --L2 or 1*L2.