The provided JavaScript for Google Apps Script targets rows in a Google Sheets document named 'leads' to delete those containing values in a honeypot field. The function starts by fetching all data from the sheet and identifies rows to delete based on the honeypot's value in column D. The script deletes the identified rows in reverse order to prevent row shifting during deletion. Users need to run the script manually for it to execute, as there is no automatic run feature for scripts in Google Sheets.
function deleteSpamRows() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("leads"); var data = sheet.getDataRange().getValues(); var rowsToDelete = []; for (var i = 1; i < data.length; i++) { var row = data[i]; var honeypotValue = row[3]; if (honeypotValue != "") { rowsToDelete.push(i + 1); } } for (var i = rowsToDelete.length - 1; i >= 0; i--) { sheet.deleteRow(rowsToDelete[i]); } }
You need to ensure that you have the necessary permissions to run this script from your Google Sheets. The script will not run automatically unless triggered by an event.
Collection
[
|
...
]