0
votes

Hi just a quick easy one, im not very experienced with scripts in sheets. I have my variables set up but i would just like to return the variable to a specific cell when the script is ran. I marked as a comment in the script below what i would like from it. Thanks!

// Menu for testing script
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Record value')
      .addItem('Record now','tester')
      .addToUi();
}

function tester() {
   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Matt");
   var value1 = SpreadsheetApp.getActiveSheet().getRange('L3').getValue();
    // i would like to append "value1" to to cell "B3" here
}
1

1 Answers

0
votes

You can use setValue(value) to append a value into a cell, keeping the original value intact:

If the destination sheet is the active sheet:

var dest = SpreadsheetApp.getActiveSheet().getRange("B3");
var original = dest.getValue();
dest.setValue(original+value1);

If the destination sheet is the named one:

var dest = sheet.getRange("B3");
var original = dest.getValue();
dest.setValue(original+value1);

References:

setValue(value)