I am trying to create a script which will hide columns where cells in a range are empty (the condition).
Below is what my table looks like, you can see there are 12 roles. I basically want to hide any columns from Role 4 onwards which are unused e.g. no values in the 3 rows.
i have a script that works (see below) but it also hides Roles 1, 2 and 3 if they are blank. I want the script to only work from Role 4 (column F) onwards. What do i need to change in the script for this to work?
P.s. I have used code from other posts to put this together so there may be lines in the code I do not need, I am still very new to google script.
function hidecolumns() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var ss = sh.getSheetByName("Project Team Resources");
var r = ss.getRange("C5:N10");
var data = r.getValues();
var rData, cData, x;
cData = data[0].map(function (col, c) {
return data.map(function (row, r) {
return data[r][c];
});
});
Logger.log(cData.length);
Logger.log(data.length);
for(var i=0;i<cData.length;i++){
if(cData[i].filter(String).length==0)
ss.hideColumns(i+3)
}
}