• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Excel SUBSTITUTE Function Trick

You are here: Home / Excel Formulas / Excel SUBSTITUTE Function Trick
Excel SUBSTITUTE Function Trick
July 13, 2011 by Mynda Treacy

Each time I write a tutorial I use the Google Keyword tool to find search phrases that are relevant. I use these phrases as tags on my post to help you find it easier in Google and other search engines.

The Google keyword tool spits out a list of phrases which I then export into Excel like the example below.

Excel Substitute Formula

Then from the list above I need to create a list of comma separated phrases.

The problem is I first need to remove the square brackets and then I need to join all of the phrases together separated by a comma and a space.

There are a few ways I can do this.

  1. Use Text to Columns to remove the square brackets then use a CONCATENATE or & (ampersand) formula to join the text together, or
  2. Use Find & Replace and then CONCATENATE to join the text together, or another way is to
  3. Use the SUBSTITUTE function to remove the square brackets and then join the text together using a cheeky Find and Replace trick in Microsoft Word.

Since most people know how to use Find & Replace (if you don’t, sign up for our online training here), and I’ve already written a tutorial on CONCATENATE, I’m going to cover the SUBSTITUTE function today.

How to Use SUBSTITUTE

First let’s tackle the text in cell A4 which is [excel substitute]

In cell C4 I will enter the following SUBSTITUTE Formula:

=SUBSTITUTE(SUBSTITUTE(A4,"[","",1),"]",", ",1)

Result:

excel substitute,

This formula is actually using the SUBSTITUTE function to replace multiple items.

The SUBSTITUTE formula in orange is replacing the left square bracket with nothing and the SUBSTITUTE formula in blue is replacing the right square bracket with a comma and a space.

How the SUBSTITUTE Function Works

SUBSTITUTE Function Syntax

=SUBSTITUTE(text, old_text, new_text, [instance_num])

Where:

Text  = the cell the text is in

Old_text = the text you want to replace. You need to put this in “double quotes”. Note this is case sensitive.

New_text = the new text you want. Again, in double quotes. If you want to replace it with nothing then simply enter two double quotes “”.

Instance_num = this specifies which occurrence of old_text you want to replace. If omitted, every instance of old_text is replaced.

Ok, now I have my formula in cell C4 I can copy it down the column then I’m ready to join the text together.

How to Join the Text Together

This is almost blasphemy for a devout Excel fan, but this is the quickest way so here goes!

  1. Copy your new text from column C.
  2. Open Microsoft Word…take a deep breath as you go to the other side
  3. In Word Paste special > Unformatted Text
  4. CTRL+H (for Find & Replace)
  5. Enter a ^p in the ‘Find what’ box. ^p is the end of the paragraph in Word.
  6. Enter nothing in the ‘Replace with’ box.

Find & Replace in Word

Tada… your text now looks like this:

excel substitute, substitute function in excel, substitute function excel, substitute formula excel, excel substitute function, excel substitute formula, excel substitute multiple, excel formula substitute, substitute excel formula,

You might be saying to yourself that I could have done that all in Word using Find & Replace and you’d be right, but that would be admitting that Word is better at some things than Excel and I can’t bring myself to do that 🙂  Plus you wouldn’t have learnt how to use the SUBSTITUTE function.

Excel SUBSTITUTE Function Trick
Mynda Treacy

Microsoft MVP logo

AUTHOR Mynda Treacy Co-Founder / Owner at My Online Training Hub

CIMA qualified Accountant with over 25 years experience in roles such as Global IT Financial Controller for investment banking firms Barclays Capital and NatWest Markets.

Mynda has been awarded Microsoft MVP status every year since 2014 for her expertise and contributions to educating people about Microsoft Excel.

Mynda teaches several courses here at MOTH including Excel Expert, Excel Dashboards, Power BI, Power Query and Power Pivot.

More Text Formulas Posts

Excel TEXT Function – handy but limited…or is it?

Excel TEXT Function – handy but limited…or is it?

The Excel TEXT Function converts numbers to text in the format you specify. It's hand for joining numbers and text together in custom chart labels etc.
Extract Text from a Cell using MID Formulas

Extract Text from a Cell using MID Formulas

Excel Test if a Range Contains Text, Numbers or is Empty

Excel Test if a Range Contains Text, Numbers or is Empty

Excel CLEAN Formula

Excel CLEAN Formula

The Excel CLEAN Function can help you to remove unwanted characters that are often imported when you copy data from web pages, but it has some limitations
Excel SUBSTITUTE Formula

Excel SUBSTITUTE Formula

The Excel SUBSTITUTE function replaces new text for old in a text string. It's an alternative to using Find and Replace by retaining the original data.
Excel Factor Entry 3 Re-format Data Using Formulas

Excel Factor Entry 3 Re-format Data Using Formulas

Use Excel's Text functions to re-format data imported from external sources
Excel SEARCH and You Will FIND

Excel SEARCH and You Will FIND

Excel TRIM Function Removes Spaces From Text

Excel TRIM Function Removes Spaces From Text

Excel TRIM function removes spaces from the start and end of text, while leaving spaces between words untouched.
Excel UPPER LOWER and PROPER Functions

Excel UPPER LOWER and PROPER Functions

Microsoft Excel’s T Function

Microsoft Excel’s T Function

The Excel T function checks whether a value is text, and returns the text if it is, or returns double quotes (empty text) if it isn’t.

More Excel Formulas Posts

Summarize Months to Quarters

Excel Formulas to Summarise Monthly Data into Quarters

3 ways (good, better, best) to summarize monthly data into quarters using formulas. Lots of examples and sample file to download.
Excel BYROW and BYCOL Functions

Excel BYCOL and BYROW Functions

Excel BYCOL and BYROW functions fundamentally change the way we write formulas that calculate across columns and down rows.
python in excel natively

How to Use Python in Excel Natively

How to use Python in Excel natively using libraries like Pandas, NumPy, Matplotlib, Seaborn and more for analysis and spectacular charts!
excel dynamic named ranges

Excel Dynamic Named Ranges

Excel Dynamic Named Ranges update automatically to include new data in the ranges referenced in your formulas and PivotTables etc.
functions for financial modelling

Excel Functions for Financial Modeling

Top 23 must know Excel functions for Financial Modeling. Includes example Excel file and step by step instructions.
excel formula by example

Excel Formula by Example

Excel can now write a formula by example. Simply give it an example or two of the result and Excel will write the formula.
ai-aided excel formula editor

AI Aided Excel Formula Editor

Save time with this free AI Excel formula editor add-in that writes, edits, improves and interprets formulas for you!
top excel functions for data analysts

Top Excel Functions for Data Analysts

Must know Excel Functions for Data Analysts and what functions you don’t have to waste time learning and why.
excel advanced formula environment

Excel Labs (Formerly, Advanced Formula Environment)

Excel Labs is a long awaited, new improved way to write, name and store Excel formulas, including LAMBDAS with the help of AI.
Pro Excel Formula Writing Tips

Pro Excel Formula Writing Tips

Must know Excel formula writing tips, tricks and tools to make you an Excel formula ninja, including a new formula editor.


Category: Excel FormulasTag: text formulas
Previous Post:Excel COUNT, COUNTA and COUNTBLANK FunctionsExcel COUNT, COUNTA and COUNTBLANK Functions
Next Post:Excel Histogram Charts and FREQUENCY FunctionExcel Histogram Charts and FREQUENCY Function

Reader Interactions

Comments

  1. Doug

    December 9, 2016 at 3:03 am

    To replace line breaks within a single cell within Excel use Find & Replace with ^j instead of ^p as you would in MS Word.

    Reply
    • Mynda Treacy

      December 9, 2016 at 8:33 am

      Nice tip, Doug. Thanks for sharing.

      Mynda

      Reply
  2. Phil

    October 26, 2016 at 4:44 am

    Well, true, Mynda, but wouldn’t it just be easier to paste the original Keyword text straight into Word and use F&R to remove the square brackets also?
    regards,
    Excel fan

    Reply
  3. Aimee

    September 18, 2015 at 10:27 pm

    Help please!

    Using Microsoft 2013, is there a quick and easy way to remove ALL non-printing characters in one easy action? The CLEAN formula was only designed to remove the first 32 non-printing characters in the 7-bit ASCII code (values 0 through 31) from text and in the Unicode character set, there are additional non-printing characters (values 127, 129, 141, 143, 144, and 157).

    The main character that causes me issues is the HTML entity;   (character 160). I used to use Find to search for spaces I can’t see using Alt while keying in 0160 – then I’d manually remove any spaces if I could find them. I presume the SUBSTITUTE formula is similar, without the manual part.

    My issue is that every type of character needs to ‘substituted’ individually. Is there a way to do them all at once?

    Hoping someone can help

    Thank you

    Reply
    • Catalin Bombea

      September 19, 2015 at 11:04 pm

      Hi Aimee,
      You can try a simple macro, that will replace all chars in a single run, in all worksheets:
      Sub FindReplace()

      Dim Wks As Worksheet
      Dim FindWhat As Variant
      Dim Chars As Variant, i As Integer
      Chars = Array(127, 129, 141, 143, 144, 157, 160)

      For Each Wks In ActiveWorkbook.Worksheets
      For i = 0 To 31 ' replace chars from 0 to 31
      Wks.Cells.Replace what:=Chr(i), Replacement:="", _
      LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
      SearchFormat:=False, ReplaceFormat:=False
      Next i
      For i = 0 To UBound(Chars) ' replace the chars listed in array
      Wks.Cells.Replace what:=Chars(i), Replacement:="", _
      LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
      SearchFormat:=False, ReplaceFormat:=False
      Next i

      Next Wks
      There are 2 loops, one to remove the chars from 0 to 31, and another to replace the chars from the Chars array: Chars = Array(127, 129, 141, 143, 144, 157, 160)
      You can add any char codes to this list.
      Cheers,
      Catalin

      Reply
  4. Wanda Ponto

    January 25, 2014 at 8:21 am

    SUBSTITUTE(SUBSTITUTE(A4,”[“,””,1),”]”,”, “,1) You have indicated what the orange and blue formula is doing in this; however, I am confused with why you indicated the instance number of 1 because there is only 1 instance of each of the brackets; one bracket is [ and one bracket is ]. I removed the 1 and I got a reference error.

    Thanks

    Reply
    • Catalin Bombea

      January 25, 2014 at 12:29 pm

      Hi Wanda,
      You can remove the 1 from both instances of SUBSTITUTE function, but don’t forget to remove the argument separator for that argument (the comma). Remove “,1” instead of just “1”.
      Cheers,
      Catalin

      Reply
  5. John

    August 30, 2013 at 2:35 pm

    Hello,
    This SUBSTITUTE function may be able to help me, but it seems limited somewhat. Is there something easier that can help me look at a range of cells, compare the data and then replace it accordingly?
    For example, look at all cells A1:A10 and if they contain ABC replace it with ‘1’, if they contain DEF replace it with ‘2’ and if they contain GHI replace it with ‘3’ etc etc. Anything other than values specified should display “N/A” or “NULL”.
    I don’t want to use IF because there are 82 values to compare and replace, and the initial range they are located in, may be anywhere between 10 cells or 100 cells.
    Essentially, I am looking at creating a macro where I highlight the cells, run the macro and the change happens.
    Thank you for your assistance.

    Reply
    • Philip Treacy

      August 30, 2013 at 7:31 pm

      Hi John,

      That sounds like something I can do with a macro. If you can send me your workbook so I can see the data it would make it easier for me to write the code.

      If you create a Helpdesk ticket you can attach the workbook to that https://www.myonlinetraininghub.com/help-desk

      Regards

      Phil

      Reply

Trackbacks

  1. Excel SUBSTITUTE Formula • My Online Training Hub says:
    September 14, 2014 at 9:34 pm

    […] I nest SUBSTITUE functions to replace two different characters at […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Popular Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

239 Excel Keyboard Shortcuts

Download Free PDF

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

Download A Free Copy of 100 Excel Tips & Tricks

excel tips and tricks ebook

We respect your privacy. We won’t spam you.

x