How to Replace Text Using the SUBSTITUTE Function in Excel

When you are cleaning up a messy, imported database in Microsoft Excel, you frequently encounter cells containing incorrect text formatting. For example, a list of dates might be formatted with underscores (2023_10_24) instead of standard hyphens (2023-10-24). While you could use Excel’s standard “Find and Replace” dialogue box to fix the entire sheet at once, doing so destroys the original, raw data. To clean the text mathematically using a formula—leaving the original raw data safely untouched—you must use the SUBSTITUTE function.

How the SUBSTITUTE Function Works

The SUBSTITUTE function is a highly precise text-replacement engine. You point it at a cell, tell it exactly which specific word or character to look for, and tell it exactly what to swap it out with.

The syntax requires three primary arguments: =SUBSTITUTE(text, old_text, new_text)

  1. text: The cell containing the raw, messy string.
  2. old_text: The exact character you want to delete (must be in quotation marks).
  3. new_text: The exact character you want to inject in its place (must be in quotation marks).

How to Replace Specific Characters

Imagine cell A2 contains the messy string 2023_10_24. You want to mathematically replace every single underscore (_) with a clean hyphen (-).

Click into cell B2 and type:

=SUBSTITUTE(A2, "_", "-")

Excel scans the entire string, rips out both underscores, injects hyphens in their exact locations, and cleanly outputs 2023-10-24. The original raw data remains completely safe in column A.

Replacing Specific Instances Only

The true power of the SUBSTITUTE function lies in its hidden, optional fourth argument: instance_num. This allows you to target a specific occurrence of a character, while completely ignoring the others.

Imagine cell A2 contains the text Quarter 1 - Project Alpha - Phase 1. You only want to change the second hyphen into a colon, so it reads Quarter 1 - Project Alpha: Phase 1. The standard “Find and Replace” tool would aggressively change both hyphens simultaneously, ruining the formatting.

By adding the number 2 to the end of the formula, you can instruct Excel to skip the first hyphen entirely and only swap out the second one:

=SUBSTITUTE(A2, "-", ":", 2)

The formula instantly outputs Quarter 1 – Project Alpha: Phase 1, providing you with surgical control over text formatting without altering the underlying raw dataset.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.