google-apps-scriptgoogle-sheetsgoogle-sheets-custom-function

Custom Function Google Sheets that displays a message containing a value from another cell


I have been working on this function and would love to display the value of a particular cell in the message that pops up.

This cell is in the same row as the "current cell" if that is of any help, I am just very lost and not even sure if this is possible.

function my2ndFunction() {
  var cell = SpreadsheetApp.getCurrentCell();
  var ui = SpreadsheetApp.getUi();
  var response = ui.alert('Do you want to start?', '', ui.ButtonSet.YES_NO);
  var output;
  if (response == ui.Button.YES) {
    cell.setValue(new Date());
  }
}

Thanks for looking!


Solution

  • You can simply add another alert message within the if condition like that:

    function my2ndFunction() {
      var cell = SpreadsheetApp.getCurrentCell();
      var ui = SpreadsheetApp.getUi();
      var response = ui.alert('Do you want to start?', '', ui.ButtonSet.YES_NO);
      var output;
      if (response == ui.Button.YES) {
        cell.setValue(new Date());
        ui.alert('The current date is: ' + new Date())
      }
    }