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?

2
  • So you just want to call one function from another? Commented Feb 21, 2020 at 16:48
  • Yes, exactly! I just don't know how. Commented Feb 21, 2020 at 18:09

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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())???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.