title: Script : Default values after edit a cell on a row
body: <p>I already have a script here for when a cell on a row is edited, another cell on the same line will be filled with a timestamp.
  It also contains an option to overwrite and / or delete when the trigger-cell is changed /blanked out again.</p>
  <p>It also works over different tab-sheets (January -&gt; March in this example). I use exactly the same structure on each month. With max. 150 lines on each Month-tab.</p>
  <p><strong>Question:</strong></p>
  <p>I don't do any programming myself (Beginner: can change things when I see the code,...).</p>
  <p>Is it possible to help me expanding this script so that not only in Column C the timestamp is filled in, but also columns D to G will be filled with data (Column D, F and G: data from a &quot;settings-tab&quot; and column D with the &quot;total&quot; in the header on same page). Trigger: after changing the value of column B.</p>
  <p>I'll try to show my specific sheet here by 2 pics.</p>
  <p><a href="https://i.stack.imgur.com/vIeZ7.png" rel="nofollow noreferrer">My sheet. (colmn B = onEdit-trigger / Columns C to G should be filled in)</a></p>
  <p><a href="https://i.stack.imgur.com/YGWSc.png" rel="nofollow noreferrer">My values on a settings-tab.</a></p>
  <p><strong>Code of the Script I use:</strong></p>
  <p>-&gt; <strong>Working</strong> for passing date in Column C. <strong>Not working yet</strong> for also passing default-values (from settings-tab or total-value in header) to columns C, D, E, F, G after editing column B.</p>
  <p>Can someone help me with this functionalty please?</p>
  <p>Kind reagards!</p>
  <p>Script:</p>
  <pre><code>/**
  * Simple trigger that runs each time the user edits the spreadsheet.
  *
  * @param {Object} e The onEdit() event object.
  */
  function onEdit(e) {
    if (!e) {
      throw new Error('Please do not run the script in the script editor window. It runs automatically when you edit the spreadsheet.');
    }
    defaultvalueMultipleColumns_(e);
  }
  
  function defaultvalueMultipleColumns_(e) {
    try {
      var ss = e.source;
      var sheet = ss.getActiveSheet();
      
      ////////////////////////////////
      // [START modifiable parameters]
      var defaultValueSettings = [
        {
          sheetsToWatch: /^(JAN|FEB|MRT)$/i,
          columnLabelsToWatch: ['Edit cell'],
          columnValuesToWatch: [undefined],
          columnLabelsToFill: ['Default Value 1'],
          overwriteFilledCells: [false],
          eraseFilledCells: [true],
          columnLabelRow: 8,
          defaultvalueFormat: 'dd/mm/yyyy'
        },
      ];
      // [END modifiable parameters]
      ////////////////////////////////
  
      if (!ss.getActiveRange() || JSON.stringify(e.range) === '{}') {
        return;
      }
      var sheetName = sheet.getName();
      for (var s = 0, numSettings = defaultValueSettings.length; s &lt; numSettings; s++) {
        if (defaultValueSettings[s].sheetsToWatch.test(sheetName)) {
          var settings = defaultValueSettings[s];
          var columnLabelsToWatch = settings.columnLabelsToWatch;
          var columnValuesToWatch = settings.columnValuesToWatch;
          var columnLabelsToFill = settings.columnLabelsToFill;
          var overwriteFilledCells = settings.overwriteFilledCells;
          var eraseFilledCells = settings.eraseFilledCells;
          break;
        }
      }
      if (!settings || e.range.rowStart &lt;= settings.columnLabelRow) {
        return;
      }
      if (!columnLabelsToWatch.length
          || columnLabelsToWatch.length !== columnValuesToWatch.length
          || columnLabelsToWatch.length !== columnLabelsToFill.length
          || columnLabelsToWatch.length !== overwriteFilledCells.length
          || columnLabelsToWatch.length !== eraseFilledCells.length) {
        throw new Error('Mismatch between the number of values in columnLabelsToWatch and columnValuesToWatch, columnLabelsToFill, overwriteFilledCells or eraseFilledCells.');
      }
      var columnLabels = sheet.getRange(settings.columnLabelRow, /*column*/ 1, /*numRows*/ 1, sheet.getLastColumn()).getValues()[0];
      var columnsToWatch = [];
      var columnsToStamp = [];
      for (var i = 0, col = 0, numColumns = columnLabelsToWatch.length; i &lt; numColumns; i++) {
        if ((col = columnLabels.indexOf(columnLabelsToWatch[i])) &gt; -1) {
          columnsToWatch.push(col + 1);
        }
        if ((col = columnLabels.indexOf(columnLabelsToFill[i])) &gt; -1) {
          columnsToStamp.push(col + 1);
        }
      }
      if (columnsToWatch.length !== columnsToStamp.length) {
        throw new Error('Could not find as many columnLabelsToWatch as columnLabelsToFill.');
      }
      var modifiedValues = e.range.getValues();
      for (var row = 0, numRows = modifiedValues.length; row &lt; numRows; row++) {
        for (var column = 0, numColumns = modifiedValues[row].length; column &lt; numColumns; column++) {
          var modifiedValue = modifiedValues[row][column];
          var columnIndex = columnsToWatch.indexOf(e.range.columnStart + column);
          if (columnIndex === -1) {
            continue;
          }
          if (columnValuesToWatch[columnIndex] !== undefined &amp;&amp; columnValuesToWatch[columnIndex] !== modifiedValue) {
            continue;
          }
          var defaultvalueCell = sheet.getRange(e.range.rowStart + row, columnsToStamp[columnIndex]);
          var defaultvalue
            = String(modifiedValue).length
            ? new Date()
            : eraseFilledCells[columnIndex]
            ? null
            : new Date();
          if (defaultvalue &amp;&amp; !overwriteFilledCells[columnIndex] &amp;&amp; defaultvalueCell.getValue()) {
            return;
          }
          defaultvalueCell.setValue(defaultvalue).setNumberFormat(settings.defaultvalueFormat);
        }
      }
    } catch (error) {
      showAndThrowError_(error.message + ', stack: ' + error.stack);
    }
  }
  
  /**
  * Shows a message in a pop-up and throws an error with the message.
  *
  * @param {String} message The message to show and throw.
  */
  function showAndThrowError_(message) {
    showMessage_(message, 30);
    throw new Error(message);
  }
  
  /**
  * Shows a message in a pop-up.
  *
  * @param {String} message The message to show.
  */
  function showMessage_(message, timeoutSeconds) {
    SpreadsheetApp.getActive().toast(message, 'defaultvalue multiple columns', timeoutSeconds || 5);
  }
  </code></pre>