Formualizer Docs

SUBSTITUTE

Replaces matching text within a string.

SUBSTITUTE can replace all occurrences or only a specific instance.

The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.

Syntax

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

Arguments

ArgumentTypeRequiredDefault
textanyRequired—
old_textanyRequired—
new_textanyRequired—
instance_numanyOptional—

Remarks

  • Matching is case-sensitive.
  • If old_text is empty, the original text is returned unchanged.
  • With instance_num, only that 1-based occurrence is replaced.

Error cases

  • Non-positive instance_num returns #VALUE!.

Examples

Replace every occurrence of the target text.

Formula =SUBSTITUTE("A-B-A","A","X")

Expected result X-B-X

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Replace only the second occurrence.

Formula =SUBSTITUTE("A-B-A","A","X",2)

Expected result A-B-X

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Remove the target occurrences by replacing them with an empty string.

Formula =SUBSTITUTE("A-B-A","A","")

Expected result -B-

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

The occurrence index must start at one.

Formula =SUBSTITUTE("A-B-A","A","X",0)

Expected result #VALUE!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Replace all matches

Formula =SUBSTITUTE("a-b-a", "a", "x")

Expected result x-b-x

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Replace only second match

Formula =SUBSTITUTE("2024-01-2024", "2024", "FY24", 2)

Expected result 2024-01-FY24

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

FAQ

Is SUBSTITUTE case-sensitive?

Yes. It matches old_text with exact case and replaces either all or the requested instance.

Implementation

Engine source

On this page