Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
Splitting sheet text using an array to mantain unique ID

I'm using this: How to transpose and split in Google Apps Script?

Which works great in the first part (I use it to copy data an split it) but then I would need to redo it since I have 2 different separators, first time ";" second time ",".

The issue and I'm guessing it's more JS related than anything else, is that if I use the same for it splits the 2nd column vertically. I'll post examples.

Column A has the ID, Column B has the comma separated text

If I use it again to reformat it gives this:

enter image description here

I would like it to be split into Column B and C.

I figured it was because the for loop only pushes 2 rows, but I can't solve adding a third.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Issue:

If I understood it correctly, you have something like this:

enter image description here

And you would like to end up with something like this:

enter image description here


Solution:

The following code will do just that, splitting (and putting into several lines) the values in the first image by ;, and then separating the quantity from the product name (accomplished by splitting the ,).

function myFunction() {
  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName("Sheet1");

  var range = sheet.getRange(2,1,sheet.getLastRow()-1,2);
  var values = range.getValues();

  var valuesToInput = [];

  for(var i = 0; i<values.length; i++){
    var productList = values[i][1].split(";");
    
    for(var j = 0; j < productList.length; j++){
      var productVariables = productList[j].split(",");
      var productQuantity = productVariables[0];
      var productName = productVariables[1];

      valuesToInput.push([values[i][0], productQuantity, productName]);
    }
  }

  var rangeToInput = sheet.getRange(2,1,valuesToInput.length, 3);
  rangeToInput.setValues(valuesToInput);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!