I have a PowerShell script that searches an Excel file for a specific value ("#N/A", from a failed VLOOKUP) that needs to have all of the rows AFTER and including that row deleted quickly.
What I have done so far:
$sheetRange = $sheetData.UsedRange
$colRange = $sheetData.Range("F1")
[void] $sheetRange.Sort($colRange)
$fileWorking.Save()
$strFinder = "#N/A"
$rngSearch = $sheetData.Range("F1").EntireColumn
$txtFound = $rngSearch.Find($strFinder)
$RowFound = ($txtFound.Row)
for (($i = $RowFound); ($i -le $rowsTrans); $i++)
{
$currRow = $sheetData.Cells.Item($i).EntireRow
[void]$currRow.Delete()
}
$fileWorking.Save()
The problem is, there are over 200k rows, and I need to delete the entire range instead of one row at a time. While I have muddled around with the syntax some, I can't quite figure out the proper syntax or methods that accomplish this.
Obviously, the for loop simply needs to go, and I need to set the entire range between $RowFound and $rowsTrans... but how is that done?
...Range("A2, A4, A10, A19").entireRow.DeleteThat uses a range object definition much like a union of range objects.