Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9843

Google App Script to Hide & Show Rows Based on Dropdown Selection on Active Sheet

$
0
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'

Viewing all articles
Browse latest Browse all 9843

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>