Conversation
…nsion; clamp both ends but keep range-relative offset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a regression introduced in 8.5.0 (still present in 8.6.3) where
XLOOKUP,VLOOKUP,HLOOKUPandMATCHreturn#N/Awhen the lookup range starts before the first populated cell of the worksheet (lookupRange.Address.FromRow < Worksheet.Dimension.FromRow).Root cause
In
XlookupScanner,GetMaxItemsRow/GetMaxItemsColumnswere changed to useGetAddressDimensionAdjusted(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 asmaxItems.However, the scanning loop reads values with
GetOffset(ix, 0), which is relative to the range's ownFromRow/FromCol. When the dimension starts after the range start,maxItemsbecomes 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 iteratesGetOffset(startOffset + ix, ...), returningstartOffset + ixas 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
IRangeInfoimplementations (RangeInfo, external and in-memory) without touching eachGetAddressDimensionAdjusted.