title: how to run google script only when cell c2 in sheet "Daily #s WK1" is changed
body: <p>i need a script that can run only if cell c2 in sheet &quot;Daily #s WK1&quot; is changed this is the code i have  it open and closes cells</p>
  <pre><code> function onChange() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName(&quot;Daily #s WK1&quot;);
    var currentRange = ss.getRangeByName(&quot;NamedRange1&quot;);
    var rangeStart = currentRange.getRow();
    var values = currentRange.getValues();
  var index = 0, rows = 1;
    var show = !(values[0][40] == &quot;&quot; );
  for (var i = 1, length = values.length; i &lt; length; i++) {
  if (values[i][0] == 1 ) {
  if (show) {
   sheet.showRows(rangeStart + index, rows);
   show = false;
  index = i;
  rows = 1;
  } else
  rows++;
  } else {
  if (show)
   rows++;
  else {
  sheet.hideRows(rangeStart + index, rows);
  show = true;
  index = i;
  rows = 1;
  }
  </code></pre>