hLookUp() Function

1. Function Syntax

hLookUp(v, array, n, [type])

hLookUp(v, array, n, [type], [startIndex], [occurrence])

The hLookUp() function searches the top row of array for the value v. If a match is found, the function returns the value from the same column and the n‑th row of the array.

2. Extended Variant: startIndex and occurrence

The extended variant adds two parameters:

startIndex — Positive values specify where searching begins (1 = top‑left cell, 2 = next cell, etc.). Negative values specify where searching ends (−1 = bottom‑right cell, −2 = preceding cell, etc.).

occurrence — Specifies which occurrence of the matching value to return. Positive values count matches top‑down (1 = first match, 2 = second match, etc.). Negative values count matches bottom‑up (−1 = last match, −2 = second‑to‑last, etc.). Occurrences are counted relative to startIndex.

3. Search Type

The type argument determines how the search is performed. It may be one of the basic modes (0, 1, −1) or a sum of SEARCH:: flags.

3.1 Basic Search Modes

3.2 SEARCH:: Flags

Instead of using 0, 1, or −1, you may specify a sum of SEARCH:: flags:

3.3 Pattern Matching vs. Regular Expressions

3.4 Type Equivalents

1 = SEARCH::SortAscending + SEARCH::MatchNotGreater
−1 = SEARCH::SortDescending + SEARCH::MatchNotSmaller
0 = (0)

If type is omitted, it defaults to 1.

4. Flag Compatibility Rules

SEARCH::Pattern and SEARCH::RegEx cannot be used with:

SEARCH::MatchNotGreater and SEARCH::MatchNotSmaller cannot be used with SEARCH::FirstMatch or SEARCH::LastMatch.

If neither SEARCH::FirstMatch nor SEARCH::LastMatch is specified, linear search returns the first match, while binary search may return any match.

5. Sorting Requirements

If SEARCH::SortAscending or SEARCH::SortDescending is used:

Binary searches are typically tens or hundreds of times faster than linear searches.

6. Mixed Data

If SEARCH::MixedData is specified:

7. Performance Tip

If a workbook contains many hLookUp() calls, you may use the numeric sum of flags instead of individual names for faster evaluation.

8. Error Handling

If no match is found, hLookUp() returns #N/A!.

9. Examples

=hLookUp(2, {1, 2, 3; "a", "b", "c"}, 2, 0)

returns "b"

=hLookUp(2.5, {1, 2, 3; "a", "b", "c"}, 2, -1)

returns "c"

=hLookUp(2.5, {1, 2, 3; "a", "b", "c"}, 2, 1)

returns "b"

=hLookUp("*bc??", {"abc", "abcde", "ac"; 1, 2, 3}, 2, 0)

returns 2

=hLookUp(2.5, sheet1!b5:d10000, 2, SEARCH::SortAscending + SEARCH::MatchNotGreater)

=hLookUp("bc\d", {"abc", "abcde", "abc10"; 1, 2, 3}, 2, SEARCH::RegEx,,)

returns 3

10. Insert hLookUp() Automatically

You can insert hLookUp() with two clicks using Insert → HLOOKUP(). The dialog box determines optimal parameters, presets options, and builds the formula automatically.

Insert HLOOKUP dialog

11. Source Range List

The 16‑element source range list is global and stored in the settings file. New ranges are added in a circular manner using:

“Copy as Location”

Copy as Location

The “Enter” toolbar button

Enter toolbar button