I have been trying to find solutions for this for a few days now and can't seem to get anything to work.
The script below shows/hides columns in the tabs and works perfectly in the named sheet. I just need it to run through all of the tabs, except for the first few,and be applied in them too.
I just don't understand how it all works so am getting stuck.
All help hugely appreciated!!!!!!
function hidecolumns() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Jun 2025 2HR');
var first_row = sh.getRange(2,1,1,sh.getMaxColumns()).getValues().flat();
first_row.forEach((fr,i)=>{
if(fr==0){
sh.hideColumns(i 1);
}
else {
sh.showColumns(i 1);
}
})
}
CodePudding user response:
Running the function for all but a few sheets and all columns of each sheet
function hidecolumns() {
const ss = SpreadsheetApp.getActive();
const xsh = ["Sheet0", "Sheet1", "Sheet2"];
ss.getSheets().filter(s => !~xsh.indexOf(s.getName())).forEach(sh => {
sh.getRange(2, 1, 1, sh.getMaxColumns()).getValues().flat().forEach((fr, i) => {
if (fr == 0) {
sh.hideColumns(i 1);
}
else {
sh.showColumns(i 1);
}
})
})
}
CodePudding user response:
This script cycles through all the tabs, after the third, and works perfectly. The main issue is there are over 100 tabs. Ideally it would cycle through tabs 4-12 and then 80-the end, which would make it less time consuming to run. Can i just change i<totalsheets to i<13,i>79 ??
function hidecolumns() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var totalSheets = sheets.length;
for(var i=3;i<totalSheets;i )
{
var first_row =
sheets[i].getRange(3,1,1,sheets[i].getMaxColumns()).getValues().flat();
first_row.forEach((fr,j)=>{
if(fr==0){
sheets[i].hideColumns(j 1);
}
else {
sheets[i].showColumns(j 1);
}
})
}
}`