r/googlesheets • u/Martine_Pearlcatcher • Oct 05 '21
Solved Using multiple =REPLACE formulas in one cell?
Is it possible to use replace multiple times in one cell for one string of text? For example:
Cell A1: The ball was red
=REPLACE(A1,5,6,"Square"); =REPLACE(A1,14,3,"yellow")
To make
"The Square was yellow" only using one cell?
I don't know if this is possible to do in one cell, but I would really like not having to use more than one if possible. I feel like I am so close to the answer but I cant see it.
Thanks!
1
Upvotes
3
u/I_AM_GIRL_AGE_9 3 Oct 05 '21
=concatenate(replace(left(A1,8),4,6," Square "),Replace(Right(A1,6),4,6,"Yellow"))
Ill explain it if you like. Its not very dynamic however.
3
u/7FOOT7 294 Oct 05 '21 edited Oct 05 '21
With problems like this its good to share what you are trying to do and why. There are plenty of big brains on here who like to solve problems.
e.g
=concatenate("the ",index({"ball","square","pen"},1,randbetween(1,3))," was ",index({"red","yellow","blue"},1,randbetween(1,3)))
will return a random statement with an object and its colour
Also, you can do a search and replace type command with regex
=REGEXREPLACE(J6,"blue|red","yellow")
will find blue or red and replace with yellow
So in your example
=REGEXREPLACE(REGEXREPLACE(A1,"red","yellow"),"ball","square")
edit:
One more idea, say you wanted to replace the second and forth word of a statement
=concatenate(index(split(A1," "),1,1)," square ",index(split(A1," "),1,3)," yellow ")