Hi everyone and happy new year.
I am completely new to Apps Script and finding the switch from VBA very difficult.
I have a sheet with the range A1:AU309 and have a reference number in the first row and column so that if the number shown is a "0" the row or column will hide automatically.
I have butchered a code together which although works takes about a minute to run. When the code was specifically for just hiding rows it took about 2 seconds to run. Is anyone able to help highlight where I am going wrong or an alternative code to speed up the process??
function onEdit(e){
var sheet = SpreadsheetApp.getActive().getSheetByName("Purchase Orders");
var data = sheet.getDataRange().getValues();
var numCols = sheet.getMaxColumns();
for(var i = 1; i < data.length; i++) {
if(data[i][0] === 1) {
sheet.showRows(i+1);
} else if(data[i][0] === 0) {
sheet.hideRows(i+1);}
for(var ai = 0; ai < numCols; ai++){
if(data[0][ai] == 0){
sheet.hideColumns(ai+1);
} else {
sheet.showColumns(ai+1);
}
}
}
}
Many thanks
Lee