Hippyjim
Hippyjim

Reputation: 2522

Google Spreadsheet store some values in other cells

I'm trying to get started with scripting in Google Spreadsheets.

How do I store values in cells? I try to use setValues but I don't have permission. I wanted to have a protected range of cells track all the names entered in cells that have this function. The below script only stores one name as a test, but it doesn't work.

function storeNames(name) {

  var sheet = SpreadsheetApp.getActiveSheet(); 
  var storeRange = sheet.getRange(6,2);
  storeRange.setValues([[name]]);
  return "Hello " + name;
}

So in cell A1, I set the function =storeNames(B1)

I enter a name in B1, and A1 gives an error as it can't store the name entered in another cell - how do I keep a list of the names entered? Anyone got any tips on how to debug this - all the usual javascript tools don't work, and the script editor log won't work for scripts executed in the spreadsheet, so I'm flying blind.

Upvotes: 0

Views: 1250

Answers (1)

wchiquito
wchiquito

Reputation: 16551

A simple example, is something like:

/* CODE FOR DEMONSTRATION PURPOSES */
function onEdit(e) {
  var range = e.range, sheet = range.getSheet();
  if (sheet.getName() === 'Sheet1' && range.getColumn() === 2)
    sheet.getRange(range.getRow(), 1).setValue(e.value);
}

Upvotes: 1

Related Questions