Remove keywords that don't contain

This script removes keywords that "don't contain" the following words... "weight loss and semaglutide." Please feel free to swap out the words in the script.

  1. Open Google sheets

  2. Select "Extensions" then "Apps scripts"

  3. Paste the following script

function removeRows() {
  // Open the active spreadsheet and the active sheet
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues(); // Get all data in the sheet
  
  // Loop through rows in reverse to avoid skipping rows when deleting
  for (let i = data.length - 1; i >= 1; i--) { // Start from the bottom row, skip the header
    const keyword = data[i][0].toLowerCase(); // Convert to lowercase for comparison
    
    // Check if the keyword column (Column A) contains "sewer" or "sewage"
    if (!keyword.includes("sewer") && !keyword.includes("sewage")) {
      sheet.deleteRow(i + 1); // Delete row (adjust for 0-index)
    }
  }
  
  SpreadsheetApp.flush(); // Ensure changes are applied
}
  1. Change the words in the script to whatever words you want

  2. Run script

Last updated