Skip to content Skip to sidebar Skip to footer

Google App Script To Append Value From One Cell To String Of Numbers In Another Cell

I’ve been trying to figure out how to write a script which will take the value from one cell and append it to the end of a string of numbers in another cell of that same row. The

Solution 1:

To be as specific as I can, what I need help with is to first know if something like the appending is even possible in Google App Scripts.

Seeing the expected result, it's inserting rather than appending, as the string should be added before the last character (]). Anyway, yes, this is possible by using JavaScript string handling methods.

  • Use getValue() to the get the cell values, both the Current GPA and the GPA History.
  • One way is to use replace

Example using pure JavaScript:

var currentGPA = 3.5var gpaHistory = '[2,3.1,2.4]';
gpaHistory = gpaHistory.replace(']',','+currentGPA+']');
console.info(gpaHistory)

Once you get the modified gpaHistory, use setValue(gpaHistory) to add this value to the spreadsheet.

Post a Comment for "Google App Script To Append Value From One Cell To String Of Numbers In Another Cell"