Home > Net >  Delete rows with specific values
Delete rows with specific values

Time:10-30

I'm using this part of my script to delete each row where there is value : admin

$i = 1

Do {
    If ($worksheet.Cells.Item($i, 1).Value() -eq 'admin') 
      {
            $objRange = $worksheet.Cells.Item($i, 5).EntireRow
            $objRange.Delete()
        $i -= 1 
      }
      $i  = 1
}

While ($worksheet.Cells.Item($i,1).Value() -ne $null)

I would like to know how can I add some different values and delete more rows with words like : system, computer ...

Thanks !

CodePudding user response:

Use the -in collection containment operators:

$rowValuesToDelete = 'admin','system','computer'

if($worksheet.Cells.Item($i, 1).Value() -in $rowValuesToDelete) {
  # ...
}
  • Related