0

I'm looking to split a cell that have multiple values separated by "\n" via App Script. Itried a few functions that were proposed but nothing seemed to work. Below you can see a sample format and desired outcome.

Screenshot of current format versus desired output

Thanks.

2
  • 1
    Do NOT share spreadsheets/images as the only source of data, to avoid closure of the question. Make sure to add input and expected output as plain text table to the question. Click here to create a table easily, which are easier to copy/paste as well. Also, note that your email address can also be accessed by the public, if you share Google files. Commented Nov 3, 2022 at 18:52
  • Is there any maximum amount of values that can appear on a single cell? Commented Nov 3, 2022 at 22:34

1 Answer 1

2

I believe your goal is as follows.

  • You want to split each cell value with \n using Google Apps Script.
  • You want to put the split values in the vertical direction.

In this case, how about the following sample script?

Sample script:

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); // Please set your sheet name.
  const range = sheet.getRange("A2:A" + sheet.getLastRow());
  const values = range.getValues().flatMap(([a]) => a ? a.split("\n").map(e => [e.trim()]) : []);
  range.offset(0, 1, values.length).setValues(values);
}
  • When this script is run, the source values are retrieved from the column "A". And, the converted values are put in column "B".

Reference:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.