Google-sheets – Treat \n as a newline character for multiline formulas

google sheets

Given some sheet at cell A1 if I write ="foo\nbar" then foo\nbar will be rendered as shown:

enter image description here

If I manually add a newline using the shortcut cmd + opt + enter then the expected output as shown:

enter image description here

It's a problem because it makes my formulas look bad, especially if I'm adding a title row with ARRAYFORMULA.

  • Is it possible to get some type of newline character interpolated?
  • How do you format your multiline formulas?

Best Answer

You can use char(10) instead of \n so if you need to replace them you can do

=SUBSTITUTE(A1,"\n",char(10))

enter image description here

or if your building the formula from scratch you can do:

="foo"&char(10)&"bar"

enter image description here