3

I'm simply looking for how to link one cell's data into another cell as a note1.

What I have here simply errors telling me I do not have permission to setNote. :/

function noteSetter() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var cell = sheet.getRange("B2");
 cell.setNote("This is a note");
}


1: Open a Google spreadsheet->Rightclick a cell->Insert Note. I want data from, say A1 a string "Moo", to link into another cell, B1, so B1 has a note attached to it with the content of cell A1 "Moo". When you then hover your cursor over B1, the note pops up with "Moo".

4
  • 1
    How do you mean "as a note"? Feb 21, 2014 at 8:34
  • Open a Google spreadsheet->Rightclick a cell->Insert Note. I don't think I can make this more clear. I want data from, say A1 a string "Moo", to link into another cell, B1, so B1 has a note attached to it with the content of cell A1 "Moo". When you then hover your cursor over B1, the note pops up with "Moo". Feb 21, 2014 at 11:24
  • What is the exact error message you get? Feb 22, 2014 at 12:43
  • 1
    @Paul: Comments are temporary. You should edit your post to include that information in your question.
    – ale
    Jul 5, 2014 at 23:23

1 Answer 1

1

I can't manage to get by the permission error, this might work for you.

function onEdit(e) {
  var sheet = SpreadsheetApp.getActiveSheet();
  if (sheet.getName() == "Project"){ //Change to your sheet name
    var sourceRange = e.source.getActiveRange();
    var sourceRow = sourceRange.getRow();
    var sourceColumn = sourceRange.getColumn();
    var sourceValue = sourceRange.getValue();

    if(sourceColumn == 1){ //Change to the column you want to get the value from
      var noteCell = sheet.getRange(sourceRow, 2); //The cell where the Note should be, B-column on the current row
      noteCell.setNote(sourceValue);
    }
  }
}

EDIT
I do believe this is what you want. The function above sets a note on the cell in the B-column on the current row, if the cell in the A-column is edited.

If you don't want the note to update with A1 you should be able to use the function you wrote, with a slight modification to get the value from A1.

function noteSetter() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var cell = sheet.getRange(2, 2);
 cell.setNote(sheet.getRange(1,1).getValue());
}

function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
  name : "Set cell note",
    functionName : "noteSetter"
  }];
  sheet.addMenu("Scripts", entries);
};

I added a function to add the script to a Custom menu, to make it easier to access, if you don't want that you can just remove the onOpen-function.

11
  • Ill edit my post to reflect what I have currently. Im not trying to use a formula in a note, im trying to use a formula inside a cell that can set its own note as another cells string value. However setComment (nor setNote, the are different things) doesn't seem to work in anything except the OnEdit function. Feb 21, 2014 at 22:31
  • This goes back to my original question; how can I do this in a cell formula? When I try I simply get the error above "You do not have permission to call setNote" Feb 23, 2014 at 6:06
  • Your code works for me. But when you say that you do this in a cell formula, do you mean that you write the code in the cell itself? Feb 23, 2014 at 10:36
  • Yes its in the cell itself as I need it to have a relative affect on other cells. Mar 4, 2014 at 10:11
  • How do you write script in a cell? I've never done that. Mar 4, 2014 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.