0

I am trying to create code that will automatically hide or show rows depending on the selection of the dropdown on whatever sheet is currently active. The drop down selection is a list of all the months in the year. I want to selectively hide rows because my template sheet populates out to 31 days so there is some overrun for months that have less days that that.

I took code from several other questions and have been experimenting with trying to find a way to make it do what I want, but have been completely unsuccessful. It is important that this code specifically functions on whatever sheet is currently active because there will be multiple sheets in this document and I don't want to call them by name. Here is the code I have, and I appreciate any help that anyone can give me.

function onEdit(e) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var lastrow = sheet.getLastRow();
  var long = ['January','March','May','July','August','October','December']
  var medium = ['April','June','September','November']
  var short = ['February']

  if(e.range.columnStart==2 && e.range.rowStart==3 && e.range.getSheet().getName()=='Sheet2') {//add your sheet name
    if(e.value==long) {
      e.range.getSheet().showRows(147,15);
    }
    if(e.value==medium) {
      e.range.getSheet().hideRows(157,5);
    }
    if(e.value==short) {
      e.range.getSheet().hideRows(147,15);
    }
  }
}

//'February'

//'April','June','September','November'

//'January','March','May','July','August','October','December'
  • Related : Show/Hide Rows based on text in a cell – Rubén Dec 13 '19 at 15:38
  • This doesn't really do what I need. Any code I have seen only has one TRUE and one FALSE value where as I have a list of true values since there are multiple different months in each category that should either hide or show the row that represent the 31st day of the month. I saw this post that you recommended in my searches, but it isn't exactly what I need I think. – No Name Dec 13 '19 at 21:22

Your Answer

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

Browse other questions tagged or ask your own question.