1
Goal
Make a recursion within the function SALVARHISTO()
so that the function is called again, if the cell A8
is not found.
What I tried to
I tried to put a condition at the end, if the A8 cell was not empty, the function would run until I found the A8 cell empty. Someone can help me?
Code
function SALVARHISTO() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A7:L7').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Histórico'), true);
spreadsheet.getRange('7:7').activate();
spreadsheet.getActiveSheet().insertRowsBefore(spreadsheet.getActiveRange().getRow(), 1);
spreadsheet.getActiveRange().offset(0, 0, 1, spreadsheet.getActiveRange().getNumColumns()).activate();
spreadsheet.getRange('A7').activate();
spreadsheet.getRange('\'Produção mensal\'!A7:L7').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getActiveRangeList().setBackground('#dbe5f1')
.setBorder(true, true, true, true, true, true, '#000000', SpreadsheetApp.BorderStyle.SOLID)
.setBorder(false, false, false, false, false, false)
.setBorder(null, null, true, null, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID)
.setBorder(null, null, null, true, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);
spreadsheet.getRange('A7').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Produção mensal'), true);
spreadsheet.getRange('A6').activate();
var x = sheet.getRange('A8');
if( x != " "){
function SALVARHISTO(){}
}else{
return 'Salvo com sucesso.';
}
};
Hello Camilla, if you put 3 bass accents (```) before and after your code, it will stay
monoespaçado
and easier to read here at Stackoverflow.– Allan Juan
I don’t think trying to solve this problem is such a good idea. You will be running this function
SALVARHISTO
many times per second (maybe tens, hundreds or thousands). Put asetTimeOut
of 1 second would be something better, but perhaps it is possible to make use of listeners for that reason.– Rafael Tavares
That
function SALVARHISTO(){}
declares a function and does not execute the function– Costamilam
For you to perform a function with recursiveness just call it again within the function. SALVARHISTO(). Speechless Function in front
– Bruno Cunha
Hello @Brunocunha, I believe that really is the problem, will q you can add as answer?
– Caputo