0

I am right now working on a project with a sheet with multiple tabs in it. I am trying to get multiple functions to run, one of which I found here at stackexchange.

Here is the function:

    function addFirstRow() {
    var firstRow = 1;
    var sh = ss.getActiveSheet();
    var lCol = sh.getLastColumn();
    var range = sh.getRange(firstRow, 1, 1, lCol);
    var formulas = range.getFormulas();
    sh.insertRowsAfter(1, 1);
    newRange = sh.getRange(firstRow, 1, 1, lCol);
    newRange.setFormulas(formulas);
}

I want to call this function from a separate tab in which it's going to run. I intend to create another function to do this. I want to have this run when I enter information into a cell on this other tab, and then have this function create the row on my target tab. What would it look like to call this function from another one?

1 Answers1

1
function newFunction() {
  addFirstRow();//Just called another function
  addSecondRow();//And another
  var r=getSomeData();//call another function that returns data
}

Here try this:

function newFunction() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var name=sh.getName();
  SpreadsheetApp.getUi().alert(Utilities.formatString('Sheet Name: %s',name));//modal dialog
  sh.getRange('A1').setValue('I am ' + name);
  var ui=HtmlService.createHtmlOutput(sh.getRange('A1').getValue());
  SpreadsheetApp.getUi().showModelessDialog(ui, 'Sheet Name');//Modeless dialog
}

Documentation Reference

Check the help references in the script editor:

enter image description here

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • So I could do something like... var name=getName() while having the function called in the variable pulling data from specific cells however I designate (such as with getActiveCell().getValue())??? – Stephen Foltz Feb 21 '20 at 19:20