Attached is a test spreadsheet that shows the issue.
VLOOKUP fails in the special case where all of the following is true:
- “approximate match” is set to TRUE
- the vlookup range only contains a single row
- the range starts somewhere other than in the first (i.e. ‘A’) column.
The spreadsheet we have been given to work with has this failing case in hundreds of places inside it.
Here’s a code sample (in Kotlin) that shows the issue happening:
val worksheet = worksheets["Sheet1"]
listOf(
"just one vlookup true, false, A539:D539 -- passes ",
worksheet.calculateFormula("=VLOOKUP(\"a\",A539:D539,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",A539:D539,2,FALSE)"),
"just one vlookup true, false, A1:D1 -- passes",
worksheet.calculateFormula("=VLOOKUP(\"a\",A1:D1,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",A1:D1,2,FALSE)"),
"just one vlookup true, false, A7:D7 -- passes",
worksheet.calculateFormula("=VLOOKUP(\"a\",A7:D7,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",A7:D7,2,FALSE)"),
"just one vlookup true, false, G7:J7 -- true fails",
worksheet.calculateFormula("=VLOOKUP(\"a\",G7:J7,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",G7:J7,2,FALSE)"),
"just one vlookup true, false, G7:J8 -- true passes if range has more than one row",
worksheet.calculateFormula("=VLOOKUP(\"a\",G7:J8,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",G7:J8,2,FALSE)"),
"just one vlookup true, false, B2:E2 -- true ",
worksheet.calculateFormula("=VLOOKUP(\"a\",B2:E2,2,TRUE)"),
worksheet.calculateFormula("=VLOOKUP(\"a\",B2:E2,2,FALSE)"),
).forEach { println(it) }
The above produces the output:
just one vlookup true, false, A539:D539 -- passes
15000.0
15000.0
just one vlookup true, false, A1:D1 -- passes
15000.0
15000.0
just one vlookup true, false, A7:D7 -- passes
15000.0
15000.0
just one vlookup true, false, G7:J7 -- true fails
#N/A
15000.0
just one vlookup true, false, G7:J8 -- true passes if range has more than one row
15000.0
15000.0
just one vlookup true, false, B2:E2 -- true
#N/A
15000.0
image.png (34.9 KB)
vlookup-single-row-problem.xlsx.zip (7.0 KB)