Text functions
LEN
Matches all 48 recorded answers
Recorded: 48 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | LEN |
| Bulgarian | LEN |
| Czech | LEN |
| Danish | LÆNGDE |
| German | LEN |
| Greek | LEN |
| English (Australia) | LEN |
| English (United Kingdom) | LEN |
| English (United States) | LEN |
| Spanish | LARGO |
| Estonian | LEN |
| Finnish | PITUUS |
| French | NBCAR |
| Hebrew | LEN |
| Croatian | LEN |
| Hungarian | HOSSZ |
| Indonesian | LEN |
| Italian | LEN |
| Japanese | LEN |
| Korean | LEN |
| Lithuanian | LEN |
| Latvian | LEN |
| Norwegian | LENGDE |
| Dutch | LENGTE |
| Polish | DŁ |
| Portuguese (Brazil) | LEN |
| Portuguese (Portugal) | NÚM.CARAT |
| Romanian | LEN |
| Russian | ДЛСТР |
| Slovak | LEN |
| Slovenian | LEN |
| Serbian (Latin) | LEN |
| Swedish | LÄNGD |
| Thai | LEN |
| Turkish | UZUNLUK |
| Ukrainian | LEN |
| Vietnamese | LEN |
| Chinese (Simplified) | LEN |
| Chinese (Hong Kong) | LEN |
| Chinese (Traditional) | LEN |
Names from Microsoft's support site.
What it does
LEN(text)
LEN returns the number of characters in a text string. Microsoft's article adds the
clarification readers most often need: "Spaces count as characters." LEN measures the stored
text, not the displayed text and not the visible ink.
The entire subtlety of this function is the word character, and Excel's own answer to it has
changed. The Handbook's value-universe chapter records the historical model — worksheet text is
a sequence of UTF-16 code units, so a character outside the Basic Multilingual Plane
occupies two units and LEN of a single emoji is 2. Microsoft's current article records a
change to exactly that:
in workbooks set to Compatibility Version 2,
LENhas improved behavior with surrogate pairs, counting them as one character instead of two, while variation selectors (commonly used with emojis) are still counted as separate characters.
So LEN is now a two-answer function, and which answer you get is a property of the
workbook, not of the input. A page that states one number for LEN("😀") without naming the
compatibility version is stating half a fact.
Note also what the change does not cover: a variation selector still counts on its own. So a composed emoji — a base character, a variation selector, possibly a zero-width joiner and a skin-tone modifier — still counts as several under Compatibility Version 2, even though it renders as one glyph. The counting unit under Version 2 is the Unicode code point, not the grapheme cluster.
Arguments
text — required; the article describes it as the text whose length you want, and states that
spaces count. It is a text argument, so numbers and logicals convert first: LEN of a number
is the length of that number's General rendering, which is why LEN(1/3) is a large number and
not something meaningful about the value.
There is no second argument — no counting mode, and in particular no way to ask for the other compatibility version's answer.
Try it
Quirks
Result and edge cases
The return kind is Number, always a non-negative integer.
- Empty text is 0; an empty cell converts to empty text and is likewise 0.
LENtherefore cannot distinguish a blank cell from a cell containing=""— useISBLANK. - Trailing spaces count, which is the standard way of detecting them:
LEN(a)<>LEN(TRIM(a)). - Formatting never counts. A cell displayed as
$1,234.57holding the number 1234.567 has theLENof1234.567, not of the display. Compose withTEXTwhen the display is what you mean. - The cell text cap is 32,767 code units, so
LENon ordinary cell content is bounded by that; values built inside a formula are bounded the same way (chapter 01).
Errors
The article lists no error conditions for LEN, and the function has no domain to violate.
Reachable errors are the shared ones: an error value in the argument propagates, and a value
kind with no text conversion surfaces #VALUE! under the shared coercion rules
(chapter 02).
How to implement
Notes for implementers
- The counting unit is a declared axis, not a detail. Three candidates are live — UTF-16 code units, Unicode code points, grapheme clusters — and Microsoft's documentation now places Excel on the first for legacy workbooks and the second for Compatibility Version 2, explicitly not the third.
- Compatibility version is an observation-context axis. Any claim about
LENon astral text has to name it, in the same way a numeric claim names the Excel build. The Handbook's existing observation-context vocabulary already carries a workbook-mode field; this is what it is for. - Ill-formed UTF-16 is reachable. The value-universe chapter records interop truncation producing a dangling high surrogate. A code-point counter must decide what an unpaired surrogate contributes before it meets one.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
LEN · 9 lines · calc-func/src/catalogue/text_functions.rs on GitHub5 len_fn "LEN" (1, 1) [V "text"] |s, a, sv| {
let text = text_arg(s, a, 0)?;
let count = if count_surrogate_pairs(s)? {
k::len_character_count(&text)
} else {
text.len_utf16_code_units()
};
s.number(count as f64)
}
Kernels shared with other functions
count_surrogate_pairscatalogue/text_functionstextported/text_kernelsslice_character_countported/text_kernelscharacter_scan_endported/text_kernelslen_character_countported/text_kernels
Argument and result plumbing
text_argcatalogue/kit
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Recorded variants
| Excel build | CPU | Recorded behaviour | Our Rust | Evidence |
|---|---|---|---|---|
| Compatibility Version 1, all Excel versions | Any | A surrogate pair counts as two characters. | Implemented; selected by the workbook's Compatibility Version. Code | https://support.microsoft.com/en-gb/excel/compatibility-versions · |
| Compatibility Version 2, Excel for Microsoft 365 | Any | A surrogate pair counts as one character. Characters combined from several code points still count separately. | Implemented; selected by the workbook's Compatibility Version. Code | https://support.microsoft.com/en-gb/excel/compatibility-versions · |
Alternatives
Relationships
LENBis the byte-counting variant. Microsoft's article now states in one line that "the LENB function is deprecated", and the Handbook publishes it as a separate entry because it is a different function. SeeLENBfor what byte counting means and for what the current documentation no longer says about it.LEFT,RIGHT,MIDindex into the same string in the same units, which is why they belong to one family:LEFT(a, LEN(a))should beaunder any consistent unit choice, and that identity is the cheapest self-consistency test for an implementation.TRIMandCLEANare the usual companions when aLENresult is surprising: the extra characters are almost always whitespace or control characters.SUBSTITUTEunderlies the standard counting idiomLEN(a)-LEN(SUBSTITUTE(a,x,"")), which counts occurrences ofx— an idiom whose correctness depends onLEN's unit andSUBSTITUTE's matching using the same unit.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents