skip to Main Content

The options in the dropdown are Completed, In Progress, and Followup. I only want to hide the row when Completed is selected. Is there a way to achieve this?

Tried the following function

function onEdit(e) { 
    const columns = [3]; 
    const { range } = e;
    if (!columns.includes(range.columnStart) || !range.isComplete()) return; 
    range.getSheet().hideRows(range.rowStart); 
}

2

Answers


  1. try:

    function onEdit(e) {
      // Get the active sheet and the event range
      var sheet = e.source.getActiveSheet();
      var range = e.range;
    
      // Check if the edited cell is in column C
      if (range.getColumn() == 3) { 
        // Get the value of the edited cell
        var cellValue = range.getValue();
        
        // Check if the cell value is "Completed"
        if (cellValue == "Completed") {
          // Get the row number of the edited cell
          var row = range.getRow();
          
          // Hide the row
          sheet.hideRows(row);
        }}}
    
    Login or Signup to reply.
  2. You were close

    From

    function onEdit(e) { 
        const columns = [3]; 
        const { range } = e;
        if (!columns.includes(range.columnStart) || !range.isComplete()) return; 
        range.getSheet().hideRows(range.rowStart); 
    }
    

    To

    function onEdit(e) { 
        const columns = [3]; 
        const { range, value } = e;
        if (!columns.includes(range.columnStart) || value !== 'Completed') return; 
        range.getSheet().hideRows(range.rowStart); 
    }
    

    Notes:

    • isCompleted() is not method of Class Range.
    • Beside the range property, the on edit event object might include a value property. This property is included when a single cell is edited, except if the cell value was cleared. The To version makes use of this property.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search