# SUBSTITUTE in Google Sheets: syntax and examples

URL: https://goingstellar.ro/reference/sheets/substitute/

SUBSTITUTE swaps one piece of text for another inside a string. It works on matching text, not on positions, so it suits cleaning spaces, dashes and codes. Give an occurrence number to change just one match.

## Syntax

```
SUBSTITUTE(text_to_search, search_for, replace_with, [occurrence_number])
```

## Arguments

- `text_to_search` (string, required: yes): The text to change.
- `search_for` (string, required: yes): The piece of text to find. Case matters.
- `replace_with` (string, required: yes): The text that takes its place. An empty string removes the match.
- `occurrence_number` (number, required: no): Which match to replace, counted from 1. Without it, all matches change.

## Examples

The examples use this table, starting in A1:

| Text |
|---|
| a-b-c-b |
| Hello World |
| 2026-11-29 |
| Tel: 0722 123 456 |

```
=SUBSTITUTE(A2, "-", "/")
```

Result: `a/b/c/b`

Every dash becomes a slash. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=SUBSTITUTE(A2, "b", "X", 2)
```

Result: `a-b-c-X`

Only the second b changes. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=SUBSTITUTE(A4, "-", "")
```

Result: `20261129`

An empty replacement deletes the dashes. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=SUBSTITUTE(A5, " ", "")
```

Result: `Tel:0722123456`

Strip the spaces from a phone number. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=LEN(A2) - LEN(SUBSTITUTE(A2, "-", ""))
```

Result: `3`

Count how many times a character appears: compare the length before and after removing it. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=SUBSTITUTE(A3, "world", "Sheets")
```

Result: `Hello World`

Lowercase search text does not match World, so nothing changes. Run in a Google Sheet (English US locale) on 2026-11-29.

## Common errors

- The search is case sensitive: "world" does not find World, and the text comes back unchanged without any error.
- occurrence_number 0 does not mean none: it replaces every match, as if the argument were missing. A number larger than the match count leaves the text as it was.
- A search text that does not appear gives no error, only unchanged text. Compare the result with the original when you clean a whole column.
- To change characters by position, not by content, use REPLACE instead.

## Compared with Excel

Same syntax and case rules as Excel SUBSTITUTE.

## Questions and answers

### How do I remove a character from a cell in Google Sheets?

Use SUBSTITUTE with an empty string as the third argument: =SUBSTITUTE(A2, "-", ""). Nest several SUBSTITUTE calls to remove more than one character.

## Related functions

- [REPLACE](https://goingstellar.ro/reference/sheets/replace/)
- [REGEXREPLACE](https://goingstellar.ro/reference/sheets/regexreplace/)
- [TRIM](https://goingstellar.ro/reference/sheets/trim/)
- [LEN](https://goingstellar.ro/reference/sheets/len/)
- [FIND](https://goingstellar.ro/reference/sheets/find/)
- [SEARCH](https://goingstellar.ro/reference/sheets/search/)

## Sources

- [SUBSTITUTE (Docs Editors Help)](https://support.google.com/docs/answer/3094215)

