23

I need to add a tooltip (mouser over a cell) in a Google spreadsheet.

I want the tooltip text to be taken from another cell, some idea?

Thanks in advance!

Rubén
  • 34,714
  • 9
  • 70
  • 166
sergio
  • 273
  • 1
  • 2
  • 6

1 Answers1

27

Consider using notes - they appear when you hover mouse over cells in a spreadsheet. You can add notes manually by clicking the right mouse button on a cell and selecting 'insert note'. This can also be done programmatically.

Say, you've got 2 adjacent cells. We'll use text from the second cell to add a note to the first one. enter image description here

You can create the note with the text from the second cell using the following code.

function addNote() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var targetCell = sheet.getRange("A1");
  var sourceCell = sheet.getRange("B1");

  var noteText = sourceCell.getValue();

  targetCell.setNote(noteText);

}

Here's the end result after executing the function enter image description here

You can modify the code to make it run only when the sheet is edited and dynamically update the note when the text in the source cell changes.

Anton Dementiev
  • 5,451
  • 4
  • 20
  • 32
  • Glad I could help. Please mark the question as resolved if it solves your issue. – Anton Dementiev Jun 17 '17 at 14:42
  • Thanks a lot! It works, I would have preferred a solution that would allow me to modify the style of the note, but it is more than enough and very simple – sergio Jun 17 '17 at 15:09
  • 2
    I am new to custom functions in google sheets. Can you please tell how to "execute the function". I went to Tools > Script Editor. I then wrote the above code in the editor and saved it. How to "execute/use" this function in the spreadsheet? – Urvah Shabbir Feb 07 '18 at 17:56
  • 1
    In the dropdown list, select your function and click the 'play' button http://prntscr.com/ibia1f. Please refer to the official GAS documentation on Sheets service. It has lots of examples https://developers.google.com/apps-script/guides/sheets – Anton Dementiev Feb 07 '18 at 18:11
  • Any keyboard shortcut to add a note? – tomyo Jul 31 '18 at 18:24
  • 4
    Doesn't work to me. "You do not have permission to call setNote (line 14)." – Rodrigo Araujo Oct 23 '18 at 20:10
  • Getting the same error as @RodrigoAraujo, despite allowing my script access to my sheet. Some more detailed instructions would be great, as otherwise this seems like a really good answer. – Amos M. Carpenter Apr 07 '19 at 08:36
  • Maybe this has been solved already, but setNote cant really be called. I dont think Google sheets allows you to use custom functions to change cell contents. – Sriram May 10 '21 at 12:24