Text function

SEARCHB function

Like SEARCH (case-insensitive, wildcards), but returns the position in bytes, counting CJK characters as 2 when a DBCS language is the default.

Available in All versions of Excel, including Microsoft 365, Excel for Mac and Excel for the web

In every Excel versionWorks in Google Sheets

Syntax

SEARCHB(find_text, within_text, [start_num])
ArgumentWhat it means
find_textRequiredThe text to look for; ?, * and ~ work as in SEARCH.
within_textRequiredThe text or cell to search.
start_numOptionalByte position to start from. Default 1.

Returns: The byte position of the first match.

How SEARCHB works

SEARCHB combines the convenience of SEARCH - no case sensitivity, wildcard support - with byte counting. It is designed for Japanese, Chinese and Korean text processed with byte-based functions such as MIDB and LEFTB: in the legacy double-byte character sets, kanji, kana, hangul and full-width characters use 2 bytes each and Latin letters and digits 1.

Byte counting only happens when a double-byte (DBCS) language - Japanese, Chinese (Simplified or Traditional) or Korean - is set as the default editing language under File > Options > Language. With any other default language every character counts as 1 byte and the B version behaves exactly like the normal one.

Use the position SEARCHB returns only with other B functions. Mixing a byte position with MID, which counts characters, gives wrong slices.

Examples

1Position of a ward (Japanese default language)

B2fx=SEARCHB("港",A2)
AB
1Address
2東京都港区7

Result: 7

Three kanji (6 bytes) come first, so 港 starts at byte 7. SEARCH would return 4.

2Case-insensitive match in mixed text (Japanese default language)

B2fx=SEARCHB("B",A2)
AB
1Code
2東京abc6

Result: 6

Case is ignored, so B matches b. 東京 takes 4 bytes and a the 5th, so b is at byte 6.

3English default language

B2fx=SEARCHB("港",A2)
AB
1Address
2東京都港区4

Result: 4

Without a DBCS default language each character is one byte, so the result equals SEARCH.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!No match, or start_num is out of range.Wrap in IFERROR.

Tips

  • To cut the text after the match, pair it with MIDB: =MIDB(A2,SEARCHB("港",A2),100).
  • Wildcards count as they do in SEARCH; a ? matches one character whether it is 1 or 2 bytes.

Google Sheets

SEARCHB also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

SEARCHB in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
FrenchCHERCHERB
GermanSUCHENB
PolishSZUKAJ.TEKST.B
RussianПОИСКБ
SpanishHALLARB