Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Office Scripts Delete Entire Rows Based on Multiple Data in Certain Cells

I am a non-programmer and quite new to Office Scripts and I would love some help.

I am currently trying to delete entire rows if the cell in the "Change Flag" column, which happens to be the second column on the Excel sheet, contains the word "Delete" or "Deleted".

I managed to delete rows if they contain the word "Delete" with the following script but could not make the script cells with "Deleted" too. I tried throwing brackets in there but it unfortunately did not work.

Can someone suggest a best practice to handle the deletion of rows based on multiple text matches (delete if x = y OR z)?

function main(workbook: ExcelScript.Workbook) {
    // Get the used range on the current sheet.
    const currentSheet = workbook.getActiveWorksheet();
    let table = workbook.getTables()[0];
        // Get the RangeAreas object for each cell with a formula.
    const usedRange = currentSheet.getUsedRange();   
  //get the values of the range
    let values = usedRange.getValues();
    //get the row count of the range
    let rowCount = usedRange.getRowCount();
    //starting at the last row, check if the cell in column '1' equals to 'Delete'. If it is, then delete the entire row.
    for (let i = rowCount - 1; i >= 0; i--) {
        if (values[i][1] == "Delete") {
            usedRange.getCell(i, 1).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up)
        }
    }
}
about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Your if statement should look like the below:

if (values[i][1] == "Delete" || values[i][1] == "Deleted")

If you are looking for more general tutorials, here is a page I found that explains if statements a little more: https://www.w3schools.com/jsref/jsref_if.asp

about 4 years ago · Santiago Gelvez Denunciar

0

You can use the includes() method of the string object to do this. To use that method, you'd have to cast the value to a string using the toString() method like so:

if (values[i][1].toString().includes("Delete"))

Using includes, it will flag for both Delete and Deleted.

The words Delete and Deleted may be spelled in a variety of different ways (e.g. delete and deleted, DELETE and DELETED, etc.). Those different spellings will not be flagged by includes(). If want those different spellings to be evaluated in the same way, you can use a method like toLowercase() to do that. After calling that method, you'd just provide the includes() method with a lowercase version of the spelling like so:

if (values[i][1].toString().toLowerCase().includes("delete"))

This approach will also flag for any other text that includes delete. So if you have text in a cell like "this row should not be deleted" this code will flag that text as well.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda