XLOOKUP のワイルドカードと部分一致

既定の XLOOKUP はアスタリスクをただの文字として扱う。このシートで SKU-10* を探すと、指定した missing が返った。第 5 引数 match_mode を 2 にして初めてワイルドカードになり、最初の一致 SKU-101 の価格 12.5 が返った。後続の SKU-103 や SKU-10X ではない。Google と Microsoft の XLOOKUP 説明は、どちらも 2 をワイルドカードモードとしている。

目次

要点

既定の XLOOKUP はアスタリスクをただの文字として扱う。このシートで SKU-10* を探すと、指定した missing が返った。第 5 引数 match_mode を 2 にして初めてワイルドカードになり、最初の一致 SKU-101 の価格 12.5 が返った。後続の SKU-103 や SKU-10X ではない。Google と Microsoft の XLOOKUP 説明は、どちらも 2 をワイルドカードモードとしている。

=XLOOKUP("SKU-10*",A2:A6,B2:B6,"missing")

確認のポイント

疑問符は 1 文字に一致する。SKU-10? も最初は SKU-101 に当たる。SKU-110 は SKU-10? には合わないが SKU-1*0 には合い、その検索は 4.1 を返す。見つからない場合は missing のまま。この引数を省略すると、未ヒットは通常 N/A になる。ワイルドカードの失敗と混同しないこと。

注意点と互換性

リストには文字どおりのキー A*B-9 があり、完全一致では価格 99 が見つかる。ワイルドカードモードでも A*B-9 は「A、その後任意、その後 B-9」に合うので、ここでも 99 が返った。モード 2 でアスタリスクそのものを探すなら、Microsoft はチルダでエスケープすると書いており、このファイルでは A~*B-9 も 99 だった。小文字の sku-10* も SKU-101 に当たる。ワイルドカードにしただけで大文字小文字は区別されない。

英語の詳細例・数式・著者メモ

I typed this and expected the first SKU that started with SKU-10:

=XLOOKUP("SKU-10*",A2:A6,B2:B6,"missing")

The cell said missing. The list in A2:A6 was SKU-101, SKU-103, SKU-110, A*B-9, and SKU-10X. Nothing in that list is the literal text SKU-10*, and by default XLOOKUP is not doing a wildcard search. The asterisk is just another character.

The fifth argument is match_mode. Google’s XLOOKUP help calls 2 a wildcard match. Microsoft’s XLOOKUP function page says the same, and it spells out that *, ?, and ~ have special meaning in that mode. Once I passed 2, the formula moved:

=XLOOKUP("SKU-10*",A2:A6,B2:B6,"missing",2)    → 12.5
=XLOOKUP("SKU-10?",A2:A6,B2:B6,"missing",2)    → 12.5
=XLOOKUP("SKU-1*0",A2:A6,B2:B6,"missing",2)    → 4.1
=XLOOKUP("ZZ*",A2:A6,B2:B6,"missing",2)        → missing

12.5 is the price on SKU-101, the first row that matches SKU-10*. SKU-103 and SKU-10X also fit that pattern. XLOOKUP does not return all of them, and it does not pick the “best” one. It returns the first hit, which is the same first-match rule I already see in the exact-match XLOOKUP vs INDEX/MATCH vs VLOOKUP write-up.

? is one character. SKU-10? matches SKU-101, SKU-103, and SKU-10X. It does not match SKU-110 (SKU-11 plus a 0). SKU-1*0 is the one that landed on SKU-110 and returned 4.1.

A miss with an if_not_found string stays that string. Drop the "missing" argument and a real miss is #N/A, which is the usual lookup error path.

When the SKU itself contains an asterisk

One of the keys in the test list is the literal text A*B-9, priced at 99. Exact mode finds it, because that is the actual cell value:

=XLOOKUP("A*B-9",A2:A6,B2:B6,"missing")        → 99

Turn wildcard mode on and the same lookup still returns 99. That is not proof of an exact match. In mode 2, A*B-9 means “A, then anything, then B-9,” and A*B-9 happens to fit its own pattern. If another row such as AXB-9 appeared above it, I would expect that earlier row to win. I did not add that row, so I am not going to write down a result I did not see.

To look up the asterisk as a character in mode 2, Microsoft’s page says ~ is the escape. In this file:

=XLOOKUP("A~*B-9",A2:A6,B2:B6,"missing",2)     → 99

That found the literal A*B-9 key. Use the tilde when the stored SKU might contain * or ? and you still need wildcard mode for other searches.

Case is not a wildcard problem

=XLOOKUP("sku-10*",A2:A6,B2:B6,"missing",2)    → 12.5

Lowercase sku-10* still hit SKU-101. Wildcard mode did not become case-sensitive. If the list can hold both SKU-103 and sku-103 with different prices, this is the wrong function; I walked through that mess in Case-Sensitive Lookup.

FIND and SEARCH are a different tool if you are inspecting a single string rather than walking a column. SEARCH already treats * and ? as wildcards; FIND does not. That comparison is in FIND vs SEARCH.

I did not test VLOOKUP with a TRUE / approximate match as a substitute, and I did not test FILTER with a regex. If you need every SKU-10* row, not the first, XLOOKUP is the wrong function anyway.

Oscar

表計算の数式とトラブル解決を紹介。検証環境と未確認事項は各記事を参照。

Google Sheets, 12 Nov 2026, tab XWild. Wildcard behavior also checked against Microsoft’s and Google’s XLOOKUP pages; not re-run in desktop Excel.

次の記事:検索と条件付き集計 XMATCH と MATCH の違い