Note: The other languages of the website are Google-translated. Back to English

Strip or remove html tags from text strings

If there are multiple text strings which are surrounded with the html tags, to remove all of the html tags, the methods in this article may do you a favor.


Strip or remove all simple html tags with formula

If your text strings are surrounded with some simple html tags, the MID function in Excel can help you to solve this job. The generic syntax is:

=MID(string,text_start,LEN(string)-tag_len)
  • string: the text string or cell value that you want to remove the html tags from.
  • text_start: the number of the position that the first character located which you want to use.
  • tag_len: the length of the html tags within the text string.

Please copy or enter the following formula into a blank cell:

=MID(A2,4,LEN(A2)-7)

Then, drag the fill handle down to the cells that you want to apply this formula, and all the html tags have been removed from the cells as below screenshot shown:


Explanation of the formula:

LEN(A2)-7: This LEN function is used to calculate the length of the text string in cell A2, and subtracts 7 (the number of the html tags, both the beginning and ending tags) means to get the number of characters that you want to extract which exclude the html tag. The returned value will be used as the num_chars argument within the MID function.

MID(A2,4,LEN(A2)-7): This MID function is used to extract all the characters that start at the fourth character, and the length of the string is the num-chars that returned by the LEN function.


Strip or remove some complex html tags with VBA code

If there are multiple html tags within the text string as below screenshot shown, the above formula may not work correctly, in this case, the following VBA code can help you to deal with some complex html tags in text strings.

1. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following VBA code in the Module Window.

Sub RemoveTags()
'updateby Extendoffice 
    Dim xRg As Range
    Dim xCell As Range
    Dim xAddress As String
    On Error Resume Next
    xAddress = Application.ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("please select data range", "Kutools for Excel", xAddress, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
    xRg.NumberFormat = "@"
    With CreateObject("vbscript.regexp")
        .Pattern = "\<.*?\>"
        .Global = True
        For Each xCell In xRg
            xCell.Value = .Replace(xCell.Value, "")
        Next
    End With
End Sub

3. Then, press F5 key to run this code, and a prompt box is popped out, please select the cells that you want to remove the html tags, see screenshot:

4. And then, click OK button, and all of the html tags have been removed from the selected cells, see screenshot:


Relative functions used:

  • LEN:
  • The LEN function returns the number of characters in a text string.
  • MID:
  • The MID function is used to find and return a specific number of characters from the middle of given text string.

More articles:

  • Remove Line Breaks From Cells In Excel
  • This tutorial provides three formulas to help you removing line breaks (which are occurred by pressing Alt + Enter keys in a cell) from specific cells in Excel.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet

Follow Us

Copyright © 2009 - www.extendoffice.com. | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL