Tell me an Excel function that extracts only one word when the same word is duplicated…
- User
Tell me an Excel function that extracts only one word when the same word is duplicated in one cell in Excel. Answer in English.
Assistant
To extract only one instance of a duplicated word within the same cell in Excel, you can use a combination of Excel functions. Since there's no single, straightforward function for this specific task, we'll combine a few to achieve the desired outcome. Here's a step-by-step approach using the
FILTERXML,Split, andUNIQUEfunctions, which are available in Excel 2019 and later versions, including Office 365.For Excel 2019 and Later (Including Office 365):
Assuming the text with duplicated words is in cell
A1.-
Formula to Extract Unique Words:
code=UNIQUE(FILTERXML("<t><d>" & SUBSTITUTE(A1, " ", "</d><d>") & "</d></t>", "//d"))- How it works:
SUBSTITUTE(A1, " ", "</d><d>")replaces each space with</d><d>, effectively wrapping each word in<d>...</d>.FILTERXML("<t><d>" & ... & "</d></t>", "//d")parses the XML string and returns an array of the text within each<d>...</d>tag, i.e., each word.UNIQUE(...)then removes duplicates from this array, leaving only unique words.
- How it works:
-
Note: This formula returns an array (a list of unique words) that spills over into adjacent cells if you're using Office 365 or Excel 2021. If you want to keep these in a single cell (though not recommended for clarity), you might need to adjust your approach based on your specific requirements.
For Earlier Versions of Excel (Without
FILTERXMLandUNIQUE):In earlier Excel versions, achieving this in a single cell with a formula is more complex due to the limitations in array handling and the absence of
UNIQUEandFILTERXML. However, you can use an array formula combined withINDEX,MATCH,ROW, andCOUNTIF, but it's more cumbersome and might not be as scalable. A more practical approach for earlier versions involves using VBA (Visual Basic for Applications) or assisting with Power Query (available from Excel 2010, but more straightforward from Excel 2016 onwards).VBA User-Defined Function (UDF) for Earlier Excel Versions:
- Open VBA Editor (Press
Alt+F11in Excel). - Insert a new Module (
Insert> ).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.