Hi Khalil,
Function FirstEmpty(what As String) As Long
Dim r As Range
If what = "row" Then
For Each r In ActiveSheet.Rows
If WorksheetFunction.CountA(r) = 0 Then
FirstEmpty = r.Row
Exit Function
End If
Next
ElseIf what = "col" Then
For Each r In ActiveSheet.Columns
If WorksheetFunction.CountA(r) = 0 Then
FirstEmpty = r.Column
Exit Function
End If
Next
End If
' no empty rows (or columns), return zero
FirstEmpty = 0
End Function
Sub test()
Debug.Print FirstEmpty("row")
Debug.Print FirstEmpty("col")
End Sub
Ed Ferrero
http://www.edferrero.com