Hi! I am trying to delete data that I selected off the listviewer I created. Everytime I try with different code blocks, the app crashes. Is there any way to do such an action without app scripting the google sheet? This is the code I have right now. If a user selects a certain team, it gives them the option to delete. I want the entire row of chosen data to be erased from Google sheet if possible. Please help!
function doGet(e) {
var sheet = SpreadsheetApp.openById("YOUR_SHEET_ID").getSheetByName("YOUR_SHEET_NAME");
var partialText = e.parameter.partialText; // Get partial text from the URL parameter
if (!partialText) {
return ContentService.createTextOutput("Error: No search text provided.");
}
var deletedRows = deleteAllRowsByPartialColumnB(partialText, sheet);
return ContentService.createTextOutput("Deleted Rows: " + deletedRows);
}
function deleteAllRowsByPartialColumnB(partialText, sheet) {
var data = sheet.getDataRange().getValues(); // Get all data
var deletedCount = 0;
for (var i = data.length - 1; i >= 0; i--) {
// Loop from bottom to top
if (String(data[i][1]).includes(partialText)) {
// Check if column B (index 1) contains the text
sheet.deleteRow(i + 1);
// Delete the row (1-based index)
deletedCount++;
}
}
return deletedCount;
// Return number of deleted rows
}