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])| Argument | What it means | |
|---|---|---|
find_text | Required | The text to look for; ?, * and ~ work as in SEARCH. |
within_text | Required | The text or cell to search. |
start_num | Optional | Byte 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)
| A | B | |
|---|---|---|
| 1 | Address | |
| 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)
| A | B | |
|---|---|---|
| 1 | Code | |
| 2 | 東京abc | 6 |
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
| A | B | |
|---|---|---|
| 1 | Address | |
| 2 | 東京都港区 | 4 |
Result: 4
Without a DBCS default language each character is one byte, so the result equals SEARCH.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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.