I‘m currently learning Google app scripts and encounter a small problem.
Background: I‘m fetching data from an API and write it into a spreadsheet, which is mostly working fine, and then do some work with the data.
In some cases the import is not working for what ever reason. (Cell value: #ERROR!) For that cases I made a „copy“ function to copy the API data to another sheet,skipping errors. So if 1 import is broken I can work with the Last successfull one.
Problem: For one sheet the runtime was too high so I changed from this code:
function copy() {
var copyWert = "";
for (var i = 3; i < 247; i++) {
for (var j = 1; j < 4;j++) {
copyWert = SpreadsheetApp.getActive().getSheetByName('API').getRange(i, j).getValue();
if (copyWert == "#ERROR!" || copyWert == "" || copyWert == "#NAME!") {
} else {
SpreadsheetApp.getActive().getSheetByName('Copy').getRange(i, j).setValue(copyWert);
}
}
}
}
To:
function copy() {
var values = SpreadsheetApp.getActiveSheet().getRange("A2:D300").getValues();
SpreadsheetApp.getActive().getSheetByName('Copy').getRange("A2:D300").setValues(values);
}
Which is way faster,but missing the check. Any ideas?