RemcoE33

Explaining

Jun 19th, 2021 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is an event function that fires every time an change is made by a user in the sheet.
  2. function onEdit(e) {
  3.   let sh = e.source.getActiveSheet();
  4.  
  5.   //If current sheet is NOT equeal (!==) to the sheetname AND (&&) range is not equal to H3. then stop the function, So if this is true is automatically points to H3....
  6.   if (sh.getName() !== 'List of Themes' && e.range.getA1Notation() !== 'H3') return;
  7.  
  8.   //This will get the display values. Be aware!! Ifyou format a number to $50. you will get that (so you working with strings..) use getValues() instead.
  9.   //The values are storred in a 2d array. So an array that holds an array of rows: [["A1","B1","C1"],["A2","B2","C2"],etc..]
  10.   // Then values[0][1] would be: B1. (arrays are zero indexed)
  11.   let values = sh.getRange('A4:F').getDisplayValues();
  12.  
  13.   //e.value is the value of the event object. (The cell that is changed.)
  14.   switch (e.value) {
  15.   case 'Starry Corridor':
  16.       values.forEach((row, ind) => {
  17.         //If column c is true then show rows else hide...
  18.           row[2] === 'TRUE' ? sh.showRows(ind + 4) : sh.hideRows(ind + 4)
  19.       })
  20.       break;
  21.   case 'Styling Theme':
  22.       values.forEach((row, ind) => {
  23.           row[1] === 'TRUE' ? sh.showRows(ind + 4) : sh.hideRows(ind + 4)
  24.       })
  25.       break;
  26.   case 'Suggestions':
  27.       values.forEach((row, ind) => {
  28.           row[1] === 'FALSE' && row[2] === 'FALSE' ? sh.showRows(ind + 4) : sh.hideRows(ind + 4)
  29.       })
  30.       break;
  31.   case 'Complete':
  32.       values.forEach((row, ind) => {
  33.           row[1] === 'TRUE' && row[2] === 'TRUE' ? sh.showRows(ind + 4) : sh.hideRows(ind + 4)
  34.       })
  35.       break;
  36.   case 'All':
  37.   default:
  38.       sh.showRows(1, sh.getMaxRows())
  39.   }
  40. }
Add Comment
Please, Sign In to add comment