Skip to content

Fix XLOOKUP/VLOOKUP/HLOOKUP/MATCH #N/A before dimension - #2440

Open
swmal wants to merge 1 commit into
develop8from
bug/i2439
Open

Fix XLOOKUP/VLOOKUP/HLOOKUP/MATCH #N/A before dimension#2440
swmal wants to merge 1 commit into
develop8from
bug/i2439

Conversation

@swmal

@swmal swmal commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a regression introduced in 8.5.0 (still present in 8.6.3) where XLOOKUP, VLOOKUP, HLOOKUP and MATCH return #N/A when the lookup range starts before the first populated cell of the worksheet (lookupRange.Address.FromRow < Worksheet.Dimension.FromRow).

Root cause

In XlookupScanner, GetMaxItemsRow/GetMaxItemsColumns were changed to use GetAddressDimensionAdjusted(0) to avoid iterating over empty rows in open ranges (e.g. A:A). This clamps both ends of the range to the worksheet dimension and returns the clamped size as maxItems.

However, the scanning loop reads values with GetOffset(ix, 0), which is relative to the range's own FromRow/FromCol. When the dimension starts after the range start, maxItems becomes too small and the loop iterates over the empty leading rows, never reaching the actual data.

Fix

The scanner now tracks a startOffset (distance between the range's own start and the clamped start) and iterates GetOffset(startOffset + ix, ...), returning startOffset + ix as the result index.

This keeps the performance optimisation in both directions — leading empty rows and trailing empty rows are still skipped — while offset base and return index stay range-relative and correct. The fix is centralised in the scanner, so it covers all IRangeInfo implementations (RangeInfo, external and in-memory) without touching each GetAddressDimensionAdjusted.

…nsion; clamp both ends but keep range-relative offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant