Importing web data into Excel often leaves analysts struggling with unreadable HTML entities like & or ". While standard funding sources typically budget for expensive external ETL tools to clean this data, smaller teams need efficient, native workarounds. Fortunately, utilizing built-in Excel formulas grants you immediate, automated decoding capabilities at zero additional cost. As a stipulation, note that methods like FILTERXML require specific Windows configurations, whereas nested SUBSTITUTE chains offer cross-platform stability. For example, using =FILTERXML("<t>"&A1&"</t>", "//t") quickly converts basic entities. Below, we outline the exact formulas, limitations, and step-by-step conversion workflows.
When you export data from web applications, scrape websites, or pull information from APIs into Microsoft Excel, you often encounter messy text filled with HTML entities. Common web symbols turn into cryptic codes: & represents an ampersand (&), < and > stand for less-than and greater-than signs, and numeric codes like ' represent apostrophes.
These entities make your data hard to read, break standard text searches, and ruin your reporting. While Excel does not feature a single, built-in DECODEHTML function, you can solve this problem using several different techniques. Depending on your Excel version and data volume, you can use nested formulas, modern Power Query workflows, XML parsing hacks, or custom VBA scripts.
If your data only contains a handful of standard HTML entities, the most straightforward approach is to nest multiple SUBSTITUTE functions inside one another. This method requires no macros, works on all versions of Excel (including Excel Online and Excel for Mac), and calculates instantly.
The standard syntax for a nested substitute formula targeting the five most common XML/HTML entities is:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, "&", "&"), "<", "<"), ">", ">"), """, """"), "'", "'")
SUBSTITUTE(A2, "&", "&") finds every occurrence of & in cell A2 and replaces it with a normal ampersand.SUBSTITUTE takes that cleaned result and replaces < with <.>, double quotes (represented by """" in Excel formulas), and the numeric apostrophe (').While safe and highly compatible, this method becomes unmanageable if your text contains dozens of different named or numerical entities (like , ©, or é). Excel formulas are limited in character length, and nesting more than 10–15 functions makes your spreadsheet difficult to audit and maintain.
If you are running Excel 2013 or later on Windows, you can leverage the FILTERXML function. This function is designed to parse XML documents. Since XML natively decodes standard entities, we can wrap our text in basic XML tags and let Excel's parsing engine do the heavy lifting automatically.
To decode standard entities in cell A2, use this formula:
=FILTERXML("<t>" & A2 & "</t>", "//t")
By prepending <t> and appending </t> to your text, you create a valid, single-node XML string. The FILTERXML function reads this string, interprets the nodes, and automatically decodes standard XML entities (like &, <, >, ', and ") when it returns the inner text value.
This trick will return a #VALUE! error if your text contains an unescaped raw ampersand (&) that is not part of a valid entity. If your source text is a mix of already-decoded and encoded characters, wrap the formula with an error handler or stick to the nested SUBSTITUTE method.
If you are processing large datasets, importing CSVs, or setting up automated data pipelines, Power Query is the most robust tool for the job. Power Query features a native web-decoding engine that handles all HTML5 entities flawlessly.
To clean your text using Power Query, follow these steps:
Html.Table([OriginalColumnName], {{"Column1", ":root"}}){0}[Column1]
Note: Replace [OriginalColumnName] with the actual name of your column containing the HTML entities.
This approach handles complex characters, foreign language accents, currency symbols, and web-specific tags without breaking or requiring complex mathematical logic.
For users who want a custom, reusable formula like =DecodeHTML(A2) directly inside their grid, a short Visual Basic for Applications (VBA) macro is the perfect solution. By using the Windows HTML Document Object Model, we can parse and decode strings instantly using the browser's native capabilities.
To add this function to your workbook:
Alt + F11 to open the VBA Editor.Function DecodeHTML(ByVal htmlText As String) As String
Dim htmlDoc As Object
On Error GoTo CleanUp
' Create an in-memory HTML document
Set htmlDoc = CreateObject("htmlfile")
htmlDoc.Open
' Write the encoded text to the document body
htmlDoc.write htmlText
' Retrieve the decoded inner text
DecodeHTML = htmlDoc.body.innerText
htmlDoc.Close
CleanUp:
Set htmlDoc = Nothing
End Function
Now, you can use your custom function anywhere in your workbook just like a native Excel formula:
=DecodeHTML(A2)
This macro effortlessly handles both named entities (such as © to ©) and numerical entities (such as £ to £).
To help you select the best method for your specific project, consult this quick comparison table:
| Method | Pros | Cons | Best For |
|---|---|---|---|
| Nested SUBSTITUTE | Works everywhere; fast calculations; no macro warnings. | Hard to scale; formula text quickly becomes long and messy. | Quick fixes involving basic characters (&, <, >). |
| FILTERXML Hack | No code required; handles standard XML entities dynamically. | Fails if unescaped ampersands exist; Windows Excel only. | Users with standard XML outputs on Windows-based Excel. |
| Power Query | Decodes everything; handles millions of rows; clean automation. | Requires manual query refresh; slight learning curve. | Importing external web data, reports, and large-scale automation. |
| VBA Custom Function | Extremely flexible; simple =DecodeHTML() grid formula. |
Requires saving as .xlsm; must enable macros to run. |
Interactive dashboards and users comfortable with macro workbooks. |
By applying the right technique above, you can turn unreadable, web-scraped strings back into clean, professional, and searchable datasets inside Microsoft Excel.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.