Cleaning database exports in Excel often leaves analysts frustrated with messy HTML tags cluttering their text. While manual Find-and-Replace or complex VBA macros are traditional remedies, they are often destructive or cumbersome to maintain. Fortunately, leveraging dynamic Excel formulas grants you instantaneous, non-destructive data cleansing. As a stipulation, while formulas easily strip basic formatting tags-such as converting <b>Approved</b> to plain "Approved"-complex nested scripts may require Power Query. Below, we outline the exact formula frameworks to automate this purification process.
When you export data from content management systems (like WordPress, Shopify, or Magento), database dumps, or web scraping tools, you often end up with cells cluttered with HTML tags. Text like <strong>Special Offer</strong> <p>Save 20% today!</p> is difficult to read and impossible to use in professional reports.
Cleaning this data manually is tedious. Fortunately, Excel offers several powerful methods to strip HTML tags and convert raw code into clean, readable plain text. Depending on your version of Excel and your technical comfort level, you can use modern formulas, Power Query, VBA, or even built-in interactive tools.
If you are using Microsoft 365 or Excel for the Web, Microsoft has introduced native Regular Expression (Regex) functions. This is by far the cleanest, most efficient way to remove HTML tags using a formula.
=REGEXREPLACE(A2, "<[^>]+>", "")
A2: The cell containing the messy HTML text."<[^>]+>": This is the regular expression pattern.
< matches the opening bracket of an HTML tag.[^>]+ matches one or more characters that are not a closing bracket.> matches the closing bracket."": Replaces any matching HTML tags with nothing (an empty string), effectively deleting them.| Original Text (Cell A2) | Formula | Output |
|---|---|---|
<p>Hello <b>World</b>!</p> |
=REGEXREPLACE(A2, "<[^>]+>", "") |
Hello World! |
<a href="link">Click Here</a> |
=REGEXREPLACE(A2, "<[^>]+>", "") |
Click Here |
If you have thousands of rows of data, using formulas can slow down your workbook. Power Query (built into Excel 2016 and newer) handles data cleaning externally and is incredibly robust. It even has a built-in engine to parse HTML.
CleanText) and enter the following Power Query formula:
Html.Table([YourColumnName], {{"Text", "body", each _}}){0}[Text]
(Replace [YourColumnName] with the actual name of your column containing HTML).
If you are using Excel 2019, 2016, or older, you won't have access to the REGEXREPLACE function. However, you can easily create your own custom formula using a small snippet of VBA code.
ALT + F11 to open the Visual Basic for Applications (VBA) editor.Function StripHTML(Cell As Range) As String
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
.Pattern = "<[^>]+>"
.IgnoreCase = True
.Global = True
End With
If Not IsNull(Cell.Value) Then
StripHTML = RegEx.Replace(Cell.Value, "")
Else
StripHTML = ""
End If
End Function
=StripHTML(A2)
If you just need a quick, one-time fix and don't want to write formulas or code, you can use Excel's built-in Find and Replace wildcard feature.
CTRL + H to open the Find and Replace dialog box.<*>While this method is incredibly fast, it uses the asterisk (*) as a wildcard. This means it finds an opening bracket <, matches absolutely everything it can, and stops at the closing bracket >.
If your cell contains mathematical expressions like "If A < B and C > D", Excel will delete everything between those two symbols, destroying your actual text. Use this method with caution!
Excel's Flash Fill feature acts like a smart assistant. By providing a few examples of what your clean data should look like, Excel can automatically figure out the pattern and clean the rest of the column.
CTRL + E (or go to the Data tab and click Flash Fill).| Method | Excel Version | Best For... | Pros / Cons |
|---|---|---|---|
| REGEXREPLACE | M365 / Web | Dynamic, formula-driven cleaning of live data. | ➕ Dynamic, accurate, simple. ➖ Not available in older Excel versions. |
| Power Query | 2016 or newer | Importing recurring reports, processing millions of rows. | ➕ Highly scalable, automation-friendly. ➖ Requires manual refreshing. |
| VBA (StripHTML) | All Versions | Users on older Excel versions who want a dynamic formula. | ➕ Works on old versions. ➖ Requires saving workbook as .xlsm (macro-enabled). |
| Find & Replace | All Versions | One-off quick cleanups of basic lists. | ➕ Extremely fast, no setup required. ➖ Destructive; can accidentally delete non-HTML text. |
| Flash Fill | 2013 or newer | Simple, inconsistent patterns. | ➕ No coding or formula knowledge required. ➖ Not dynamic (won't update if source data changes). |
Once you strip HTML tags, you might still be left with HTML character entities like & (which represents "&"), " ("), or (non-breaking space).
To clean these up, you can nest your formulas inside a series of SUBSTITUTE functions. For example:
=SUBSTITUTE(SUBSTITUTE(REGEXREPLACE(A2, "<[^>]+>", ""), "&", "&"), " ", " ")
This ensures your final export is truly plain, print-ready, and reader-friendly text!
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.