I have a script that adds specific values to the last row of the sheet by clicking a checkbox (has yes/no values) and deletes the row by unchecking the same checkbox. It works fine but as it is onEdit script - it keeps on going adding values. I am trying to loop all this job to check if the value already exists and if yes - do nothing. I developed the following but it does not work - keeps adding values with every edit. Here is the code
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getActiveSheet()
var paramrange = sheet.getRange('A55:C60')
var destn = sheet.getRange(sheet.getLastRow()+1, 1)
var destnorma = sheet.getRange(sheet.getLastRow()+1, 2)
var orpac = sheet.getRange('E23')
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[0] == 'ORP Ac') {
} else{
if(orpac.getValue() == 'yes') {
var orpacn = 'ORP Ac';
var orpacnorm = '-150';
destn.setValue(orpacn)
destnorma.setValue(orpacnorm)
} else
{
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[0] == 'ORP Ac') {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}}
}
}}