Delete any existing code in the editor and paste the following script.
Save the script and give it a name.
Close the Apps Script editor and refresh your Google Sheet.
Run the function removeRowsByKeywords.
function removeRowsContainingWord() {
// Define the word to search for
const wordToRemove = "word"; // Replace "word" with the actual word you want to match
const columnToCheck = 0; // Index of the column to check (0 = Column A, 1 = Column B, etc.)
// Get the active sheet and its data
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues(); // Get all data in the sheet
// Loop through the rows in reverse to avoid skipping rows after deletion
for (let i = data.length - 1; i >= 1; i--) { // Start from the last row, skip the header
const cellValue = data[i][columnToCheck].toLowerCase(); // Convert to lowercase for case-insensitive comparison
// Check if the cell contains the word
if (cellValue.includes(wordToRemove.toLowerCase())) {
sheet.deleteRow(i + 1); // Delete the row (adjust for 0-based indexing)
}
}
SpreadsheetApp.flush(); // Ensure all changes are applied
}