How to Show/Hide sheet based on list or array values

723 views
Skip to first unread message

Tech Dee ECE

unread,
Jul 3, 2021, 7:15:55 PM7/3/21
to Google Apps Script Community
I have a script that is trying to hide multiple sheets.

Scenario: I have a spreadsheet with over 100 tabs where the teams collaborate regularly. However, there are times that going through each project sheet by sheet is cumbersome.
Therefore, I created a master sheet with all projects (each a tab) and simply added a column for each manager.  The Master is inside the shared spreadsheet.

Whenever a manager opens the spreadsheet, all sheets are hidden except the Welcome sheet. Once on the Welcome page they are prompted to enter their name and then I use a for loop to extract the pages they are responsible for. I created a temp sheet to store their unique data.  Unfortunately, I am unable to simply show those sheets.

I turned on logging and see that the correct data is in the variable, but I keep getting error: TypeError: Cannot read property 'showSheet' of null. I assumed that I didn't have data inside the sheet I was testing, but that isn't the issue. I don’t know the syntax, structure.  I’ve tried many combinations. I’m just  lost. Any help would be greatly appreciated.
 
function f_showMgrTabs() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getSheetByName('Noah');
  var lr = source.getLastRow();
  var show = source.getRange(1,1,lr,1).getValues();
  var sheets = ss.getSheetName();
  var tabs = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
 
  var mgrTabs = show.forEach(function(value){
      Logger.log(value);});
      ss.getSheetByName([mgrTabs]).showSheet();
  }
 
Below is the output from the log. There is a sheet/tab Noah and it only has 3 values in it which are the ones I want to hide/show. Please advise, thank you. I have included a link to Test Google sheet with all of the the Apps script included. 

cbmserv...@gmail.com

unread,
Jul 3, 2021, 7:53:33 PM7/3/21
to google-apps-sc...@googlegroups.com

Try this:

 

function f_showMgrTabs() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var source = ss.getSheetByName('Noah');

  var lr = source.getLastRow();

  var show = source.getRange(1,1,lr,1).getValues();

  var sheets = ss.getSheetName();

  var tabs = SpreadsheetApp.getActiveSpreadsheet().getSheets();

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

 

  var mgrTabs = show.forEach(function(value){

      Logger.log(value);

      ss.getSheetByName(value).showSheet();

      });

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6e17a182-7642-473a-bfb4-98dd34404ddbn%40googlegroups.com.

Dadee Cano

unread,
Jul 3, 2021, 10:47:51 PM7/3/21
to google-apps-sc...@googlegroups.com
Fantastic. Thanks



--
Dee M. M. III  Cano
832-494-8681 (cell)
Reply all
Reply to author
Forward
0 new messages