2

Trying to determine a way that I can use a custom menu (.createMenu) with views that will allow me to show / hide specific columns. I need the capability to pick specific multiple columns and not ranges. In the example below how can you pick a custom view from the menu (say "Customer Info") that will only show columns A, B, C, and H? Maybe another view could show "Financial".

enter image description here

  • Are you the same user who asked this question? If you plan on using this site in the future, you should register an account, so that you don't keep losing access to older posts when your browser wipes the cookies. – user79865 Aug 23 '15 at 18:26
3

Below is a rough example of how to show / hide individual columns from a Google Sheet.

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
      .addItem('Show View A', 'showViewA')
      .addItem('Show View B', 'showViewB')
      .addItem('Show All', 'showAll')
      .addToUi();
}

function showViewA() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  showAll();
  sheet.hideColumn(sheet.getRange("A1"));
  sheet.hideColumn(sheet.getRange("F1"));
}

function showViewB() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  showAll();
  sheet.hideColumn(sheet.getRange("C1"));
  sheet.hideColumn(sheet.getRange("D1"));
}

function showAll() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.unhideColumn(sheet.getRange(1, 1, 1, sheet.getLastColumn()));
}

The View A menu item hides columns A and F, while View B menu item hides columns C and D. The Show All menu item does what it says on the tin. Hopefullly the example gives a starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.