# SUBSTITUTE Function

> Replace all or one occurrence of a text in a string with SUBSTITUTE in TX Sheet Control: case-sensitive matching, instance_num, #VALUE! and an example.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Function
- **Path:** TX Sheet Control > API Reference > Formula Functions > SUBSTITUTE Function
- **227 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/substitute/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/substitute/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/substitute/llms-full.txt

---

Replace occurrences of a text in a string with another text. SUBSTITUTE replaces `old_text` in `text` with `new_text`, and is case-sensitive. When `instance_num` is given, only that occurrence is replaced; otherwise every occurrence is. An `instance_num` of zero or less returns `#VALUE!`. Use `REPLACE` to replace text at a position instead.

### Syntax

```text
SUBSTITUTE(text, old_text, new_text, instance_num)
```

Category: Text. Minimum arguments: 3. Maximum arguments: 4.

Available for supported offline calculation.

### Examples

```text
=SUBSTITUTE("a-b-b","b","x",2)
```

The formula returns a-b-x: only the second b is replaced.

Cell and range examples require appropriate input values in the referenced cells. Handle invalid arguments, formula errors and array and spill constraints.

### See Also

- [Formulas](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formulas/llms-full.txt)
- [Custom Functions and Formula Data](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/custom-functions/llms-full.txt)

---

## Nearby

- **Previous:** [STOCKHISTORY Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/stockhistory/llms-full.txt)
- **Next:** [SUBTOTAL Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/subtotal/llms-full.txt)
