Powershell and Excel. Need help getting last row of specific column.

As part of a script I am writing I am looping through the rows of an excel sheet and copy-pasting based on the content of a particular column.
Other columns in the sheet have a larger used range than this particular column, and I want to break the loop at the end of that column.
Getting last used cell row in the sheet is easy, but I’m having trouble with isolating the last used cell row for this column.

I thought the following would work:

$intLastRow = $ws.UsedRange.Columns[3].Cells.Count $count = 2 while($count -le $intLastRow){ $count++ } 

But it returns the wrong row value. The last used row in the sheet is row 749, but the last used row in the column I want is 645. The above returns 749.
($ws is a worksheet COM object)

submitted by /u/Sys_man
[link] [comments]

Leave a Reply