Cleaning raw HTML tags from web-scraped text in Excel is notoriously tedious, often stalling critical data analysis. While enterprise data budgets typically fund expensive third-party cleansing platforms, smaller operations require more accessible, immediate alternatives.
Implementing a native Excel formula grants immediate, zero-cost data refinement without software overhead. As a stipulation, note that native formulas excel with standard tags like paragraph markers, whereas highly complex nested scripts require Power Query. For example, nesting SUBSTITUTE functions successfully purges <b> tags from raw scraped descriptions. Below, we outline the exact formula syntax to streamline your data workflow.
Web scraping is an incredibly powerful way to gather data from the internet, but the raw output is rarely ready for analysis. More often than not, when you scrape text from a website, you end up with a messy mix of actual content and raw HTML markup-such as <p>, <div>, <a href="...">, and <span> tags.
While you could clean this data using Python or external tools before importing it, Excel offers several powerful ways to clean HTML tags directly inside your workbook. Depending on your version of Excel, you can use the brand-new regular expression formulas, nested legacy formulas, Power Query, or custom VBA functions. In this guide, we will walk through the best formulas and techniques to strip HTML tags from your text and leave you with clean, usable data.
For years, Excel users envied Google Sheets' REGEXREPLACE function. Thankfully, Microsoft has finally introduced native Regular Expression functions to Excel 365. If you are using an updated version of Excel 365, this is by far the easiest, cleanest, and most robust formula-based method to strip HTML tags.
=REGEXREPLACE(A2, "<[^>]+>", "")
"<[^>]+>": This is the regular expression pattern.
< matches the opening angle bracket of an HTML tag.[^>]+ matches one or more characters that are not a closing angle bracket (>). This ensures that the formula captures the entire tag, including attributes like class="..." or href="...".> matches the closing angle bracket."" (Empty String): This tells Excel to replace any matched HTML tag with absolutely nothing, effectively deleting it.This single formula handles everything from simple tags like <b> to complex hyperlinked tags like <a href="https://example.com" class="link"> in one single sweep.
Stripping the bracketed HTML tags is only half the battle. Often, web-scraped text contains encoded HTML entities such as (non-breaking space), & (ampersand), < (less-than sign), and > (greater-than sign).
To clean these up, you can nest the REGEXREPLACE function within a series of SUBSTITUTE functions. Here is how to construct a comprehensive formula that cleans both the tags and the most common HTML entities:
=SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
REGEXREPLACE(A2, "<[^>]+>", ""),
" ", " "
),
"&", "&"
),
""", """"
)
This nested formula first strips the structural HTML tags, then replaces non-breaking spaces with standard spaces, converts & to standard ampersands, and restores double quotes from their HTML entity format.
If you are working on an older version of Excel (Excel 2016, 2019, or 2021) that does not support regular expressions, you cannot easily parse arbitrary HTML using standard formulas. However, if your scraped text only contains a few known, repetitive tags (like paragraph and bold tags), you can use a chain of nested SUBSTITUTE functions.
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, "<p>", ""), "</p>", ""), "<b>", ""), "</b>", "")
Limitations: While this works for predictable formatting, it quickly becomes unmanageable if your HTML contains dynamic attributes (like varying URLs in anchor tags) because SUBSTITUTE requires an exact match to work.
If you have complex HTML or large datasets, trying to clean tags with standard worksheet formulas can slow down your workbook. Excel's Power Query engine features a highly advanced, built-in HTML parser that can extract text instantly without complex regex patterns.
You can use the Html.Table M-code formula inside Power Query to let Excel treat your scraped text like a true web document.
CleanText) and enter the following Power Query formula:
Html.Table([YourHTMLColumnName], {{"extracted_text", ":root"}})
This is arguably the most professional way to clean scraped text because Power Query automatically decodes all HTML entities and strips all structural tags behind the scenes, using the actual HTML Document Object Model (DOM).
If you don't have Excel 365 (meaning no REGEXREPLACE) and you want a simple formula you can use directly on your worksheet without loading Power Query, you can create a custom VBA function. This function uses Windows' built-in VBScript Regular Expressions library.
Function CleanHTML(ByVal htmlText As String) As String
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Pattern = "<[^>]+>"
.Global = True
.IgnoreCase = True
End With
' Strip HTML Tags
Dim cleanStr As String
cleanStr = regEx.Replace(htmlText, "")
' Clean up common HTML entities
cleanStr = Replace(cleanStr, " ", " ")
cleanStr = Replace(cleanStr, "&", "&")
cleanStr = Replace(cleanStr, """, """")
cleanStr = Replace(cleanStr, "<", "<")
cleanStr = Replace(cleanStr, ">", ">")
CleanHTML = Application.WorksheetFunction.Trim(cleanStr)
End Function
Alt + F11 to open the VBA Editor.=CleanHTML(A2)
Which method you should choose depends entirely on your environment and the complexity of your scraped data:
| Method | Excel Compatibility | Pros | Cons |
|---|---|---|---|
| REGEXREPLACE Formula | Excel 365 (Insider/Latest Updates) | Fast, dynamic, no VBA or Power Query required. | Not available in older Excel perpetual licenses. |
| Nested SUBSTITUTE | All Versions | Simple, requires no programming knowledge. | Fails if HTML tags contain dynamic classes/attributes. |
| Power Query (Html.Table) | Excel 2010 and Newer | Flawless DOM parsing, automatically decodes all entities. | Requires manual refresh; not a real-time formula. |
| VBA User-Defined Function | Excel Desktop (Windows) | Can be used as a simple cell formula in older Excel versions. | Requires saving the workbook as macro-enabled (.xlsm). |
Cleaning raw HTML from web-scraped data no longer requires switching back and forth between Excel and text editors. If you are fortunate enough to be running the latest version of Excel 365, the REGEXREPLACE formula solves the problem in a single line. For older versions, leveraging Power Query's structural HTML engine or importing a quick VBA user-defined function will keep your data pipelines clean, automated, and ready for visualization.
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.