Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140220

How to create a note on a Spreadsheet cell based on the value of the selected cell

$
0
0

To get this specific function to work, I'm trying it out in a simple test sheet.

I've got two sheets(STATUS and FEBRUARI) in the FEBRUARI sheet I've selected a certain cell. This cell has a value. What I want the script to do is to look at that value, find that value in the STATUS sheet(say it finds it in A1) and return the value in B1 to a cell note in the selected cell in the FEBRUARI sheet. As example: in the cell it says "Project 6" and the cell-note gives info about this project.

This is what I got. This gives me a certain value(-1) but it doesn't seem to matter where i put the lookupvalue.. it always returns -1.

    // My Script

function noteSetter() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var lookupvalue = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();
  var sheet = ss.getSheetByName("STATUS"); //source sheet
  var sheet2 = ss.getSheetByName("FEBRUARI"); //result sheet
  var cellnote = SpreadsheetApp.getActiveSheet().getActiveCell();
  var lc = sheet.getLastColumn()
  var lookup = sheet.getRange(1,1,1,lc).getValues() //
  var index = lookup.indexOf(lookupvalue)


  cellnote.setNote(index);


  // This part will actually run the script once it's up and running
  function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
  name : "Set cell note",
    functionName : "noteSetter"
  }];
  sheet.addMenu("Scripts", entries);
};


}

Viewing all articles
Browse latest Browse all 140220


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>