First cell in active row during script execution - google-apps-script

I am using the code below to view through a sheet, and change the first cell background to red if any other cells are red. What I would like, is to change the first cell in each row to red, only if that row contains a red cell. This code works through the spreadsheet, but only makes cell A1 red. How do I get it to affect the first cell of each row independently?
function MakeRed(){
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var first_column = "B";
var first_row = 1;
var last_row = sheet.getLastRow();
var last_column = sheet.getLastColumn();
var active_row = 1;
var range_input = sheet.getRange(1,1,last_row,last_column);
var range_output = sheet.getRange("A1");
var cell_colors = range_input.getBackgroundColors();
var color = "#ff0000";
var count = 0;
for(var r = 0; r < cell_colors.length; r++) {
for(var c = 0; c < cell_colors[0].length; c++) {
if(cell_colors[r][c] == color) {
count++;
range_output.setBackground("#ff0000");
} else {
count--;
if (count == 0) {
range_output.setBackground("#ffffff");
}
}
}
}
}

I would suggest you do the whole stuff in the array of background colors you already have instead of calling a spreadsheet service each time the condition is true.
Code becomes simpler because I used the indexOf array method in the condition
function MakeRed(){
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var first_column = "B";
var first_row = 1;
var last_row = sheet.getLastRow();
var last_column = sheet.getLastColumn();
var active_row = 1;
var range_input = sheet.getRange(1,1,last_row,last_column);
var range_output = sheet.getRange("A1");
var cell_colors = range_input.getBackgroundColors();
var color = "#ff0000";
var count = 0;
for(var r = 0; r < cell_colors.length; r++) {
Logger.log(cell_colors[r].indexOf(color));// just to check, you can remove this of course ...
if(cell_colors[r].indexOf(color)>-1) {
count++;
cell_colors[r][0]=color;
} else {
count--;
if (count == 0) {
cell_colors[r][0]="#ffffff";
}
}
}
range_input.setBackgroundColors(cell_colors);// update sheet colors
}
EDIT : I don't really understand the idea behind the "count" thing... it works the same way without it (code below) :
function MakeRed(){
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var first_column = "B";
var first_row = 1;
var last_row = sheet.getLastRow();
var last_column = sheet.getLastColumn();
var active_row = 1;
var range_input = sheet.getRange(1,1,last_row,last_column);
var range_output = sheet.getRange("A1");
var cell_colors = range_input.getBackgroundColors();
var color = "#ff0000";
for(var r = 0; r < cell_colors.length; r++) {
Logger.log(cell_colors[r].indexOf(color))
if(cell_colors[r].indexOf(color)>-1) {
cell_colors[r][0]=color;
} else {
cell_colors[r][0]="#ffffff";
}
}
range_input.setBackgroundColors(cell_colors);// update sheet colors
}
edit 2 : this version will reset col A to white if no other red cell is in the row
function MakeRed(){
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var first_column = "B";
var first_row = 1;
var last_row = sheet.getLastRow();
var last_column = sheet.getLastColumn();
var active_row = 1;
var range_input = sheet.getRange(1,1,last_row,last_column);
var range_output = sheet.getRange("A1");
var cell_colors = range_input.getBackgroundColors();
var color = "#ff0000";
for(var r = 0; r < cell_colors.length; r++) {
var rowWoColA = cell_colors[r].slice(1);
if(rowWoColA.indexOf(color)>-1) {
cell_colors[r][0]=color;
} else {
cell_colors[r][0]="#ffffff";
}
}
range_input.setBackgroundColors(cell_colors);// update sheet colors
}

Change var range_output = sheet.getRange("A1"); to the range you want edit.
You could do this in the loop:
for(var r = 0; r < cell_colors.length; r++) {
for(var c = 0; c < cell_colors[0].length; c++) {
if(cell_colors[r][c] == color) {
count++;
// Assuming you only want to change bg color of the first column on each row
sheet.getRange(r,1).setBackground("#ff0000");
} else {
count--;
if (count == 0) {
sheet.getRange(r,1).setBackground("#ffffff");
}
}
}
}

Related

Google Sheet : The result could not be auto-expanded. Please insert new columns (1)

This script import opportunities that we get. It populates rows which then calculates some numbers such as interest and stuff. However, I now have errors when populating my cells (#REF error, see pictures below). Nothing has changed so my first guess is it has do with the processing of the sheet which has become too heavy.
`
function onInstall(e) {
onOpen(e);
}
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createAddonMenu();
menu.addItem('Créer étude', 'init');
menu.addToUi();
}
function init() {
ss = SpreadsheetApp.getActiveSpreadsheet();
identifyJe();
sheetMaker = ss.getActiveSheet();
currentRow = ss.getActiveCell().getRowIndex();
ssEtudes = SpreadsheetApp.openById(getSheetEtudesId());
var ui = SpreadsheetApp.getUi();
var respon se = ui.alert(
'Ligne sélectionnée : ' + currentRow + '. Exécuter ?',
ui.ButtonSet.OK_CANCEL
);
if (response !== ui.Button.OK) return;
doEtude();
doContrat();
doPhases();
}
function doEtude(nomEtude) {
var etudeData = [];
for (var i = 0; i < etudeNamedRanges.length; i++) {
var column = ss.getRangeByName(etudeNamedRanges[i]).getColumn();
etudeData.push(sheetMaker.getRange(currentRow, column).getValue());
}
var destSheet = ssEtudes.getSheetByName('etudes');
var rowToAppend = getFirstEmptyRow(destSheet, 0);
for (var i = 0; i < etudeData.length; i++) {
var column = ssEtudes.getRangeByName(etudeNamedRanges[i]).getColumn();
destSheet.getRange(rowToAppend, column).setValue(etudeData[i]);
}
}
function doContrat() {
var contratData = [];
for (var i = 0; i < contratNamedRanges.length; i++) {
var column = ss.getRangeByName(contratNamedRanges[i]).getColumn();
contratData.push(sheetMaker.getRange(currentRow, column).getValue());
}
var destSheet = ssEtudes.getSheetByName('contrats');
var rowToAppend = getFirstEmptyRow(destSheet, 11);
for (var i = 0; i < contratData.length; i++) {
destSheet.getRange(rowToAppend, i + 4).setValue(contratData[i]);
}
}
function doPhases() {
var phasesCoords = getPhasesCoords();
var phasesData = [];
for (var i = 0; i < phasesCoords.length; i++) {
var phaseData = getPhaseData(phasesCoords[i]);
phaseData.unshift(i + 1);
phasesData.push(phaseData);
}
var destSheet = ssEtudes.getSheetByName('phases');
var rowToAppend = getFirstEmptyRow(destSheet, 9);
var columns = [];
for (var nPhase = 0; nPhase < phasesData.length; nPhase++) {
var phaseData = phasesData[nPhase];
for (var i = 0; i < phaseData.length; i++) {
if (columns[i] === undefined)
columns[i] = ssEtudes.getRangeByName(phasesNamedRanges[i]).getColumn();
destSheet
.getRange(rowToAppend + nPhase, columns[i])
.setValue(phaseData[i]);
}
}
}
`
Type of formula
The results
The error, which translates into The result could not be auto-expanded. Please insert new columns (1).
The results actually appear for some time and disappear after a few seconds, constantly. Does it have something to do with the size of the spreadsheet ?

GOOGLE SCRIPT Why a function is running when it's not called in the script?

I have a problem that I can't seem to be able to resolve. Basically, I have a Project where I have all my scripts. For some reason, all of a sudden and with no apparent reason, when I try to execute a script, it executes all the script at once... why does it happen? Specifically, I need to execute my script "copiaInEffettivo", but when I do it triggers the other 2 as well. Before this afternoon, everything was fine.
I copy here all my scripts together, but I highlight the fact that in the editor all these functions have their own separate file:
function colorazioneCaselle()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var PRAG = ss.getSheetByName("PRAG");
var colors = ss.getSheetByName("colors");
var row = 3;
var col = 2;
var cella = colors.getRange(row, col);
var valcel = cella.getValue();
var i = 0;
while (col != 47) {
while (i != 24) {
if (valcel != "") {
var x = 0;
var y = 29;
while (x != 17) {
var cella2 = colors.getRange(y, 3).getValue();
if (valcel == cella2) {
var colore = colors.getRange(y, 1).getBackgroundColor();
PRAG.getRange(row + 1, col + 1).setBackgroundColor(colore);
x = 17;
}
else if (valcel != cella2) {
y++;
x++;
}
}
}
row++;
valcel = colors.getRange(row, col).getValue();
i++;
Logger.log("cella giù");
}
col++;
row = 3;
valcel = colors.getRange(row, col).getValue();
i = 0;
Logger.log("cambio colonna")
}
}
function controlloCasellaEffettivo() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var effettivo = ss.getSheetByName('effettivo');
var info = ss.getSheetByName('info');
var row = 3;
var row2 = 3;
var col = 7;
var col2 = 5;
var cellauno = effettivo.getRange(row, col);
var luogo = info.getRange(row2, col2);
for(var y = 0; y < 27; y++)
{
var i = 0;
while(i < 155)
{
if (cellauno.isChecked() === true)
{var contenuto = effettivo.getRange(row, 3).getValues();
luogo.setValues(contenuto);
row2++;
luogo = info.getRange(row2, col2);
}
row++;
cellauno = effettivo.getRange(row, col);
i++;
}
col++;
col2++;
row2 = 3;
row = 3;
luogo = info.getRange(row2, col2);
cellauno = effettivo.getRange(row, col);
}
}
colorazioneCaselle()
function copiaInEffettivo() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pianificazione = ss.getSheetByName('pianificazione');
var effettivo = ss.getSheetByName('effettivo');
var contenuto = pianificazione.getRange(3, 3, 154, 30);
contenuto.copyTo(effettivo.getRange(3, 3));
pianificazione.hideSheet()
}
The first script basically applies color to cells based on their content, the second one extracts and transfers some informations into a sheet and the third one simply copies data from one sheet to another and then hides the first one. "ControlloCasellaEffettivo", as you can see, calls "ColorazioneCaselle" at the end. Any guesses on why this happens?

Change cell color in SheetA when value changes in SheetB in Google Sheets

I have 2 sheets: SheetA and SheetB with identical values in corresponding cells. I'm trying to change the cell color in SheetA when the value of the cell in SheetB changes. For example if cell A5 has value 10 in both sheets and I then change it to 5 in SheetB, I want the background color of the cell in SheetA to change
This is the code so far
function onEdit(e){
var sheetsToWatch = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetA");
var sheetsToEdit = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetB");
var cell = sheetsToEdit.getActiveCell(); // checking the active cell
var bg = '#faec15'
for (let i = 0; i < active_sheet.length; i++) {
if (sheetsToWatch.match(sheetsToEdit[i])) {
sheetsToWatch.getRange(cell.getRow(), cell.getColumn()).setBackground(bg);
} else {
return;
}
}
}
It can be done this way:
function onEdit(e){
var sheetB = e.source.getActiveSheet();
var sheetB_name = sheetB.getName();
if (sheetB_name != 'SheetB') return;
var sheetB_cell_value = e.value;
var sheetB_cell_row = e.range.rowStart;
var sheetB_cell_col = e.range.columnStart;
var sheetA = e.source.getSheetByName('SheetA');
var sheetA_cell = sheetA.getRange(sheetB_cell_row,sheetB_cell_col);
var sheetA_cell_value = sheetA_cell.getValue();
if (sheetB_cell_value != sheetA_cell_value) sheetA_cell.setBackground('#faec15');
}
function onEdit(e){
const sh = e.range.getSheet();
if(sh.getName() == 'SheetB' ) {
e.source.getSheetByName('SheetA').getRange(e.range.rowStart,e.range.columnStart).setBackground("#faec15");
}
}
The code works now. Please find my solution below
function onEdit() {
var sheetsToWatch = ['SheetA'];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRowIndex();
var column= cell.getColumnIndex();
var sheetName = sheet.getName();
var matchFound = false;
for (var i = 0; i < sheetsToWatch.length; i++) {
if (sheetName.match(sheetsToWatch[i])) matchFound = true;
}
if (!matchFound) return;
var sheetToEdit = ss.getSheetByName('SheetB');
var editRow = sheetToEdit.getLastRow();
var editColumn = sheetToEdit.getLastColumn();
for (var j = 1; j <= editRow; j++) {
for (var k = 1; k <= editColumn; k++){
var formula = sheetToEdit.getRange(j,k).getFormula();
var rowi= parseInt(formula.replace(/[^0-9]/g,''),10);
if (rowi == row){
if (k == column){
sheetToEdit.getRange(j,k).setBackground('#faec15');
}
};
}
}
}

Creating sheets with from master sheet

I have a sheet named form responses which gets input from google
forms,Then I created sheets with names from Column C which is
employee code and append all the respective rows from form responses
to the newly created sheets.
Now I have sheets with name as employee code ( which is in column c of the sheet). Then I want to create secondary sheets from this master sheet(sheets with name as employee code) whose name is using the column E value as attached to the Employee code.for eg : if Emp code is 10003825 and value in column E is ASR, the sheet name should be 10001515ASR.
In Column E there are only 4 values ADC,ASR ACC,RSR. let the master sheet(sheets with name as employee code) retain ADC rows always while when other rows containing ASR,ACC,RSR comes append the respective row to the newly created sheet(ie if ASR the row goes to 10001515ASR).
I have shown my present sheet and expected output
The code I developed is shown below:
function switchSheet(){
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheets = activeSpreadsheet.getSheets();
for (var i = 1; i < sheets.length; i++) {
var p = sheets[i].getSheetName();
sheetCreateChannel(p);
}
}
function sheetCreateChannel(ss){
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = activeSpreadsheet.getSheetByName(ss);
var getNames = sheet1.getDataRange().getValues();
getNames.shift();
var sheets = activeSpreadsheet.getSheets();
var sheetsObj = {};
for (var i = 0; i < sheets.length; i++) {
sheetsObj[sheets[i].getSheetName()] = sheets[i];
for (var i = 0; i < getNames.length; i++) {
var r = getNames[i];
if (r[4].toString()== "ASR"&& !((ss+(r[4])) in sheetsObj)) {
var newSheet = activeSpreadsheet.insertSheet(ss + "ASR");
sheetsObj[ss+"ASR"] = newSheet;
}
else if (r[4].toString()== "ACC"&&!((ss+(r[4])) in sheetsObj)) {
var newSheet = activeSpreadsheet.insertSheet(ss + "ACC");
sheetsObj[ss+"ACC"] = newSheet;
}
else if (r[4].toString()== "RSR"&& !((ss+(r[4])) in sheetsObj)) {
var newSheet = activeSpreadsheet.insertSheet(ss + "RSR");
sheetsObj[ss+"RSR"] = newSheet;
}
else {
break;
}
}
}
var deleteRows = 0;
for (var i = 0; i < getNames.length; i++) {
var r = getNames[i];
if (r[4].toString() != "") {
if ((ss+(r[4])) in sheetsObj) {
var Q =ss+(r[4]);
sheetsObj[Q].appendRow(r);
}
deleteRows = i + 2;
}
}
sheet1.getRange(2, 1, deleteRows - 1, sheet1.getLastColumn()).clearContent();
}
This code works fine for my above issue
function sheetCreate(){
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = activeSpreadsheet.getSheetByName("Form Responses 1");
var getNames = sheet1.getDataRange().getValues();
getNames.shift();
var sheets = activeSpreadsheet.getSheets();
var sheetsObj = {};
for (var i = 0; i < sheets.length; i++) {
sheetsObj[sheets[i].getSheetName()] = sheets[i];
}
var deleteRows = 0;
for (var i = 0; i < getNames.length; i++) {
var r = getNames[i];
var N=r[2].toString()+r[4].toString();
if (N != "") {
if (N in sheetsObj) {
sheetsObj[N].appendRow(r);
} else {
var newSheet = activeSpreadsheet.insertSheet((N));
var cell1 = newSheet.getRange("A1").setValue("Timestamp");
var cell2 = newSheet.getRange("B1").setValue("Score");
var cell3 = newSheet.getRange("C1").setValue("Employee ID");
var cell4 = newSheet.getRange("D1").setValue("Name of the ATCO");
var cell5 = newSheet.getRange("E1").setValue("The channel on which duty is performed ");
var cell6 = newSheet.getRange("F1").setValue("DATE on which duty is performed");
var cell7 = newSheet.getRange("G1").setValue("Total duration of duty done");
newSheet.appendRow(r);
sheetsObj[N] = newSheet;
}
deleteRows = i + 2;
}
}
sheet1.getRange(2, 1, deleteRows - 1, sheet1.getLastColumn()).clearContent();
}

Add an answer to the spreadsheet if a script error occurs

I haven't learned how to adjust so that if there is an error in the script when trying to capture data from openweathermat.org, the word ERROR is written in cell A10 on the Clima page of my spreadsheet.
I would like help and advice on how I should adjust the script to make this happen.
function TudoCompleto() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Clima');
var rg=sh.getRange("B12");
var vA=rg.getValues();
if (vA[0][0]=="OK"){
var spreadsheet = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Clima");
var apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXX";
var cityName = sheet.getRange("A1").getValue();
var apiCall = "api.openweathermap.org/data/2.5/weather?q=" + cityName +"&appid=" + apiKey;
var response = UrlFetchApp.fetch(apiCall);
var data = JSON.parse(response.getContentText());
Logger.log(response.getContentText());
var weather = data["weather"][0]; //It's an array
var sys = data["sys"];
var main = data["main"]
var location = data["name"];
var country = sys["country"];
var weatherDesc = weather["main"];
var temp = main["temp"];
var minTemp = main["temp_min"];
var maxTemp = main["temp_max"];
var weatherData = [
["Location:", location],
["Country:", country],
["Weather:", weatherDesc],
["Teaperture:", temp],
["Min Temp:", minTemp],
["Max Temp:", maxTemp]
];
sheet.getRange(3, 1, weatherData.length, weatherData[0].length).setValues(weatherData);
//The API Call works
// The Data will be retrieved like below JSON file.
//{"coord":{"lon":139,"lat":35},
//"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
//"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
//"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
//"wind":{"speed":7.31,"deg":187.002},
//"rain":{"3h":0},
//"clouds":{"all":92},
//"dt":1369824698,
//"id":1851632,
//"name":"Shuzenji",
//"cod":200}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "F"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "R"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("R"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "B"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "S"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("S"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 10; i++) {
var cel = "H"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "M"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("M"+u).setValue(sheet.getRange(cel).getValue());
break;
};
}
}
};
spreadsheet.getRange('Clima!A12').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('Clima!R:S').activate();
spreadsheet.getRange('Clima!I:J').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
};
In order to publish, I had to add the entire script at the request of a member to help him understand my need. I apologize for the long script.
function TudoCompleto() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Clima');
var rg=sh.getRange("B12");
var vA=rg.getValues();
try{
if (vA[0][0]=="OK"){
var spreadsheet = SpreadsheetApp.getActive();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Clima");
var apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXX";
var cityName = sheet.getRange("A1").getValue();
var apiCall = "api.openweathermap.org/data/2.5/weather?q=" + cityName +"&appid=" + apiKey;
var response = UrlFetchApp.fetch(apiCall);
var data = JSON.parse(response.getContentText());
Logger.log(response.getContentText());
var weather = data["weather"][0]; //It's an array
var sys = data["sys"];
var main = data["main"]
var location = data["name"];
var country = sys["country"];
var weatherDesc = weather["main"];
var temp = main["temp"];
var minTemp = main["temp_min"];
var maxTemp = main["temp_max"];
var weatherData = [
["Location:", location],
["Country:", country],
["Weather:", weatherDesc],
["Teaperture:", temp],
["Min Temp:", minTemp],
["Max Temp:", maxTemp]
];
sheet.getRange(3, 1, weatherData.length, weatherData[0].length).setValues(weatherData);
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "F"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "R"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("R"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 2; i++) {
var cel = "B"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "S"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("S"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
var spreadsheet = SpreadsheetApp.getActive();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // planilha ativa
var sheet = spreadsheet.getSheetByName("Clima");
for (var i = 1; i < 10; i++) {
var cel = "H"+ i //
if (sheet.getRange(cel).getValue() != "") {
for (var u = 1; i < 2000; u++) {
var cel2 = "M"+ u //
if (sheet.getRange(cel2).getValue() == "") {
sheet.getRange("M"+u).setValue(sheet.getRange(cel).getValue());
break;
}
}
}
}
spreadsheet.getRange('Clima!A12').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('Clima!R:S').activate();
spreadsheet.getRange('Clima!I:J').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}
catch(e) {
ss.getSheetByName("Clima").getRange('A10').setValue('ERROR');
Logger.log(e);
}
}