Automatically add underscores between multiple words in a cell
By Abigail Rogers •
I have a cell with multiple words and I need an underscore between them.
using
=IFERROR(LEFT(C8,MATCH(1,INDEX((MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1)),1)=" ")*(ISERROR(VALUE(MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1))-1,1))))*(ISERROR(VALUE(MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1))+1,1)))),0),0)) & "_" & MID(C8,MATCH(1,INDEX((MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1)),1)=" ")*(ISERROR(VALUE(MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1))-1,1))))*(ISERROR(VALUE(MID(C8,ROW(INDIRECT("2:" & LEN(C8)-1))+1,1)))),0),0)+1,255),C8)This is only adding the underscore to the first word.
21 Answer
If you want to change all spaces for underscores use:
=SUBSTITUTE(C8," ","_")To remove multiple spaces at the start or end of your string, use:
=SUBSTITUTE(TRIM(C8)," ","_") 2