简体   繁体   中英

Delete rows with specific values

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 !

Use the -in collection containment operators:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM