DETECTLANGUAGE returns the language code for a piece of text in Excel for Microsoft 365. Use the code to filter multilingual reviews or translate only the rows that need it.
| Function category | Text functions |
| Introduced in | Microsoft 365 |
| Returns | Language code |
| Related functions | TRANSLATE |
DETECTLANGUAGE syntax and result
=DETECTLANGUAGE(A2)Pass text or a cell reference. The result is a code such as “es” for Spanish, “fr” for French, or “en” for English. The function takes one argument and uses Microsoft’s online language service.
Identify languages in a column of reviews
Enter the formula in B2 and fill down. IF leaves blank rows unclassified. Turn on the filter in column B and select the language codes you need.
| A | B | |
|---|---|---|
| 1 | Review | Language code |
| 2 | Entrega rápida y buen embalaje | es=IF(A2="","",DETECTLANGUAGE(A2)) |
| 3 | La commande est arrivée à temps | fr=IF(A3="","",DETECTLANGUAGE(A3)) |
| 4 | The order arrived on time | en=IF(A4="","",DETECTLANGUAGE(A4)) |
| 5 | =IF(A5="","",DETECTLANGUAGE(A5)) |
Full sentences give the service more context. Short replies such as “OK,” names, and product codes can be ambiguous.
Translate rows in a different language
Detect the source language in column B and enter the target in D2. The formula in C keeps the source text when the codes match. On the other rows, it passes the source code to TRANSLATE.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Review | Source code | Result | Target code |
| 2 | Entrega rápida y buen embalaje | es=IF(A2="","",DETECTLANGUAGE(A2)) | Fast delivery and good packaging=IF(B2="","",IF(B2=$D$2,A2,TRANSLATE(A2,B2,$D$2))) | en |
| 3 | La commande est arrivée à temps | fr=IF(A3="","",DETECTLANGUAGE(A3)) | The order arrived on time=IF(B3="","",IF(B3=$D$2,A3,TRANSLATE(A3,B3,$D$2))) | |
| 4 | The order arrived on time | en=IF(A4="","",DETECTLANGUAGE(A4)) | The order arrived on time=IF(B4="","",IF(B4=$D$2,A4,TRANSLATE(A4,B4,$D$2))) | |
| 5 | =IF(A5="","",DETECTLANGUAGE(A5)) | =IF(B5="","",IF(B5=$D$2,A5,TRANSLATE(A5,B5,$D$2))) |
C4 returns the English review as it is. Column B still calls the language service to determine the code.
When to check the language code
The formula returns one code for the input. If you need to label each part of a mixed-language review, split it into separate cells first. Review codes for very short replies and names before you depend on them for a mail merge or publication.
If the function is missing, check your Microsoft 365 version. If the service reports that you reached its daily quota, wait for it to reset. Once your text is final, you can paste the verified codes as values.
LanguageDetect: detect languages locally in Excel
I built LanguageDetect for multilingual keyword lists. The XLL runs locally with the fastText lid.176 model. It recognizes 176 languages and returns the two highest-scoring language codes.
In the recording, Microsoft returns en for the German queries below, while LanguageDetect ranks de first. Compare columns B and C. fastText can also make mistakes, particularly on short or mixed-language queries.

| A | B | C | |
|---|---|---|---|
| 1 | Query | Microsoft | LanguageDetect |
| 2 | 3 wurzel in excel berechnend | en=DETECTLANGUAGE(A2) | de,91%,en,4%=LanguageDetect(A2) |
| 3 | 5te wurzel in excel | en=DETECTLANGUAGE(A3) | de,91%,en,5%=LanguageDetect(A3) |
| 4 | 5 wurzel in excel berechnend | en=DETECTLANGUAGE(A4) | de,92%,en,4%=LanguageDetect(A4) |
Column A contains queries from the recording, B shows Microsoft’s result, and C shows fastText’s top two predictions. Select a cell in B or C to copy its formula.
For example, de,91%,en,4% means a 91% score for German and 4% for English. These are rounded model scores, not the proportions of the text written in each language. The top two scores do not have to add up to 100% because the model considers other languages too.
For one query, copy the formula from column C above and fill it down. With dynamic arrays, you can pass the whole range in one formula. Empty cells return blank text.
=LanguageDetect(A2:A1000)Download and install LanguageDetect
Download both files and keep them in the same folder. This build is for 64-bit Excel on Windows. The model loads on the first call and stays in Excel’s memory. Calculations work offline.
In Excel, open File → Options → Add-ins. Select Excel Add-ins in the Manage list and click Go, then Browse and select LanguageDetect.xll. Keep lid.176.bin beside the add-in without renaming it.
The model was trained on Wikipedia, Tatoeba and SETimes text and is distributed under CC BY-SA 3.0. The fastText engine uses the MIT licence. Attribution and licence information.
Language detection without Microsoft 365
In Excel 2013, you can get language codes from an external service, paste them into a helper column, and filter the rows. If your goal is translation, GTranslate and the translation options can let the model infer the source language. These formulas return translated text. Keep a separate column when you also need language codes.