This is a very basic question, I almost feel stupid asking it.
I'm writing a function that is supposed to write the data from one cell into a NOTE from another cell in google sheets.
Everything works fine if I test from one single cell to another, but since I obvioulsy don't want it for just one cell, I want to automate it for all the other cells of the two columns:
I want B1 to return A1, B2 to return A2, B3 to return A3, etc. But the formulas I've tried only create notes with the value in B2 for all of the A cells. I understand this is a mistake in referencing and that I probably should use the dollar sign somewhere, but since I'msuper new to this, I still couldn't figure this out on my own.
Here is the function:
function addNote() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var targetCell = sheet.getRange("A1:A10");
var sourceCell = sheet.getRange("B1:B10");
var noteText = sourceCell.getValue();
targetCell.setNote(noteText);
}
Like I said, when I leave just "A1" in the first parenthesis and "B1" in the second, it works. Or even if I just copy the same code and change manually each ney copy to the single cells that I want.
If I understand you correctly, .setNotes and .getValues should do the job.
See snippet below.
function addNote() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var targetCell = sheet.getRange("A1:A10");
var sourceCell = sheet.getRange("B1:B10");
var noteText = sourceCell.getValues();
targetCell.setNotes(noteText);
}