' Return the last used row in a sheet, using the Range.End(xlDown) method
' (depends on there being no empty cells in the index column). Supply the
' sheet object, the number of header rows and a column that will be
' unbroken from top to bottom, and I'll return the row number of the last
' used row. This should work with no header rows, too. If nHdr=0 and no
' data, returns 0.
Function LastRow(ows, Optional nHdr = 1, Optional cIdx = 1)
If IsMissing(nHdr) Then nHdr = 1
If IsMissing(cIdx) Then cIdx = 1
Set oc = ows.Cells(nHdr + 1, cIdx)
Select Case True
Case oc.Value = "": LastRow = nHdr
Case oc.Offset(1, 0).Value = "": LastRow = oc.Row
Case Else: LastRow = oc.End(xlDown).Row
End Select
End Function