Introduction
In Google Sheets the SUBSTITUTE function is the go‑to tool for swapping a single piece of text for another inside a cell. However, real‑world data cleaning often demands many different replacements at once—think of converting abbreviations, fixing typos, or normalising date formats. The native approach forces you to nest one SUBSTITUTE inside another, a method that quickly becomes unreadable and hard to maintain. This article explores a more efficient workflow: using regular‑expression based functions, array formulas, and a lightweight Apps Script custom function to replace multiple values in a single, reusable expression. By the end, you’ll have a clear, scalable solution that saves time and reduces errors when handling complex text transformations.
Why the Classic SUBSTITUTE Falls Short
The built‑in SUBSTITUTE syntax (SUBSTITUTE(text, old_text, new_text, [instance_num])) replaces only one old_text per call. To change several terms you must nest calls:
=SUBSTITUTE(SUBSTITUTE(A2,"NY","New York"),"CA","California")- Adding a third or fourth replacement lengthens the formula exponentially.
- Each extra layer reduces readability, making debugging painful.
- Performance suffers on large sheets because the function is evaluated repeatedly for every nested level.
These drawbacks motivate a strategy that can handle an arbitrary list of “find → replace” pairs without deep nesting.
Leveraging REGEXREPLACE for Bulk Replacements
The REGEXREPLACE function accepts a regular‑expression pattern, allowing you to target many substrings in one pass. By constructing a pattern that groups all terms you wish to replace, you can map each match to its corresponding replacement using a clever lookup technique:
- Build a pipe‑separated pattern:
"NY|CA|TX". - Use VLOOKUP (or INDEX/MATCH) on a helper table that pairs each abbreviation with its full name.
- Wrap the lookup inside REGEXREPLACE via ARRAYFORMULA to apply it across a range.
This approach reduces a multi‑replace task to a single, readable formula and scales gracefully as the lookup table grows.
Building a Reusable Multi‑Replace Formula with ARRAYFORMULA
Combining ARRAYFORMULA, REGEXREPLACE, and VLOOKUP yields a compact, copy‑ready solution. Assume a two‑column table named Replacements (column A = “find”, column B = “replace”). The formula below processes column C (raw data) and outputs cleaned text in column D:
=ARRAYFORMULA(
IF(
C2:C="",
"",
REGEXREPLACE(
C2:C,
TEXTJOIN("|",TRUE,Replacements!A2:A),
LAMBDA(m,
VLOOKUP(m, Replacements!A:B, 2, FALSE)
)
)
)
)
Because Google Sheets now supports LAMBDA-style inline functions, the match (m) is instantly replaced by its lookup value. The formula automatically expands down the column, eliminating the need for manual copying.
Custom Apps Script Function: replaceAll()
For users who prefer a clean cell formula, a short Apps Script custom function can encapsulate the entire logic. The script below accepts a text string and a two‑dimensional array of pairs, then returns the fully transformed result:
function replaceAll(input, pairs) {
var output = input;
for (var i = 0; i < pairs.length; i++) {
var find = pairs[i][0];
var replace = pairs[i][1];
if (find !== "" && replace !== undefined) {
var regex = new RegExp(find, "g");
output = output.replace(regex, replace);
}
}
return output;
}
Use it in the sheet as:
=replaceAll(A2, Replacements!A2:B)
This custom function keeps the worksheet tidy, runs faster on large datasets, and can be extended with case‑insensitive flags or advanced regex patterns without altering the cell formulas.
Best Practices and Performance Tips
- Keep the lookup table small but comprehensive. Excessive rows increase the regex pattern length, which may slow evaluation.
- Prefer exact matches over partial ones. Anchor patterns with
\b(word boundaries) to avoid unintended replacements. - Test on a sample range first. Use CTRL+Shift+Enter to force array evaluation if automatic expansion behaves unexpectedly.
- Cache results. If the same source data is used repeatedly, store the cleaned version in a hidden helper column to prevent repeated recalculation.
- Document your replacement map. Adding a comment column explaining each pair helps future editors understand the intent.
Conclusion
While the classic SUBSTITUTE function works for single‑value swaps, it quickly becomes unwieldy for multiple replacements. By harnessing REGEXREPLACE with a dynamic lookup table, leveraging ARRAYFORMULA for automatic expansion, and optionally wrapping the logic in a lightweight Apps Script custom function, you gain a powerful, maintainable workflow that scales with any dataset. These techniques not only improve readability and speed but also empower you to manage complex text‑cleaning tasks with a single, reusable expression. Adopt the method that best fits your comfort level—formula‑only for quick edits, or a custom script for ultimate flexibility—and enjoy cleaner, more reliable Google Sheets data.








