Utility – Get First Blank Row
Scans a range of columns row by row in an Excel.Worksheet and returns the index of the first blank row within that range.
The function determines the last used row in the starting column and scans each row from StartRow up to that point, checking whether all specified columns in the row are empty.
VB
Function xlFirstBlankRow(wsSheet As Excel.Worksheet,
StartRow As Integer,
StartColumn As Integer,
EndColumn As Integer) As Integer
Dim iRow As Integer
Dim rowCount As Integer
Dim iRowIndex As Integer, iColIndex As Integer
Dim currentRowValue As String
rowCount = wsSheet.Cells(wsSheet.Rows.Count, StartColumn).End(xlUp).Row
'Check il all the cell fron StartCol to EndCol are empty
For iRowIndex = StartRow To rowCount
Dim bIsEmpty As Boolean : bIsEmpty = True
For iColIndex = StartColumn To EndColumn
currentRowValue = CStr(wsSheet.Cells(iRowIndex, iColIndex).Value)
bIsEmpty = String.IsNullOrEmpty(currentRowValue) And bIsEmpty
Next
If bIsEmpty Then
iRow = iRowIndex
Exit For
End If
Next
Return iRow
End Function