0
votes

I'm attempting to write a Google Apps Script that will duplicate a row whenever new data is entered into a row, however I have little experience with JavaScript.

I start with the function onEdit, and I want it to check the row of the newly entered value and determine whether or not each cell is occupied by a null or real value. If real, nothing happens. If null, the cell will be filled with the value of the cell in the row above it.

For example, when the value 5 enters the sheet it creates a new row. That row should be filled with the values above it except for the cell occupied by the 5.

1
Do you have an example of a script you've tried? This isn't the right site if you're just looking for people to write code for you.ross

1 Answers

0
votes

if you are new to Apps Script and do not know how to start - this is how you could implement your request:

function onEdit() 
 {
  var sheet=SpreadsheetApp.getActiveSheet();
  var lastRow=sheet.getLastRow()
  var lastColumn=sheet.getLastColumn()
  var entries=sheet.getRange(lastRow,1,1,lastColumn)
  for(var i=1; i<=lastColumn; i++)
    {
      var cell=sheet.getRange(lastRow,i).getValues() 
      if(cell==0)
      {
        var previousCell=sheet.getRange((lastRow-1),i).getValues()
        sheet.getRange(lastRow,i).setValues(previousCell)
      }
    }        
  }

I suggest however, that you have a look at the Google Apps Script Documentation, where you can find easily the functions you need to write your own script.