javascriptgoogle-apps-scriptgoogle-sheetsstring-concatenationgoogle-apps-script-editor

How to use a variable in a string in Google Sheets Script Editor?


I'm a newbie to Script Editor, so I need some help.

function makeitright(){
var app1 = SpreadsheetApp;
var ss1 = app1.getActiveSpreadsheet();
var cred = ss1.getSheetByName("Crédito");
var lastrow = cred.getLastRow(); 

var formmod = 'ISBLANK('"H"+(lastrow+1)')'')';

I'm trying to write a formula to a single cell. But this formula will always change with a new added row. So I need the formula to work with the variable that gets the lastrow + 1.

Any ideas in how this could be made?


Solution

  • replace

    'ISBLANK('"H"+(lastrow+1)')'')';
    

    by

     'ISBLANK(H' + ( lastrow + 1 ) + ')';
    

    To learn more read about how string concatenation works in JavaScript.