function onFormSubmit() {
ss = SpreadsheetApp.getActive();
sh = ss.getSheetByName('Form responses 1');
rg = sh.getDataRange().getValues();
if ( ??????????????????) {
sh.deleteRows(????????????); //deletes all rows having same Coln D, where Coln B = Coln C
}
}
function should be something like this (not tested):
function onFormSubmit() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Form responses 1');
var rg = sh.getDataRange().getValues();
//find each matching row and "blank it"
for ( var i = 0; i<rg.length; ++i ) {
if ( rg[i][1] === rg[i][2] && rg[i][3] == 25) {
sh.getRange(i+1,1,1,5).setValues([["","","","",""]]); //,,setValues array might need changing
}
}
//find the blank rows and delete them
for ( var i = 0; i<rg.length; ++i ) {
if ( rg[i][0] == "" ) {
sh.deleteRow(rg[i]);
}
}
I ammended the sript, it is saved. I created the trigger also onFormSubmit
But when the data comes in, it is deleting just that one row. Not all Rows, having the same file Number
function onFormSubmit() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Form responses 1');
var rg = sh.getDataRange().getValues();
//find each matching row and "blank it"
for ( var i = 0; i<rg.length; ++i ) {
if ( rg[i][1] === rg[i][2] && rg[i][3] == 25) {
sh.getRange(i+1,1,1,5).setValues([["","","","",""]]); //,,setValues array might need changing
}
}
//find the blank rows and delete them
for ( var i = 0; i<rg.length; ++i ) {
if ( rg[i][0] == "" ) {
sh.deleteRow(rg[i]);
}
}
}
You need to decide how to get the "Token" value into your script, or if it is needed at all?
Anyway here is a working script with Token value hardcoded to 25:
function condRowDel() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('delrows');
var rg = sh.getDataRange().getValues();
var rows = [];
for ( var i = 0; i<rg.length; ++i ) {
if ( rg[i][1] === rg[i][2] && rg[i][3] == 25) {
sh.getRange(i+1,1,1,5).setValues([["","","","",""]]);
}
}
var newrg = sh.getDataRange().getValues();
for ( var i = 0; i<newrg.length; ++i ) {
if ( newrg[i][0] == "" ) {
sh.deleteRows(i+1,1);
}
}
}
File Token Value will be taken only if value in Column B = Value in Column C
Only then ALL rows with that File Token Value will be Deleted
This script is also only deleting the last row uploaded with File Token. It shud delete ALL ROWS with File Token = 25 (in this case). Only value in cells is deleted. Leaves a blank row when subsequent data comes in