View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default first empty cell

How about:

Option Explicit
Function EmptyCell(col As String, startRow As Long)
Dim eCell As Range
'If Col,startRow is empty return startRow
'If Col,startRow is not empty search down and return row of first empty cell
If IsEmpty(Range(col & startRow)) Then
Set eCell = Range(col & startRow)
ElseIf IsEmpty(Range(col & startRow + 1)) Then
Set eCell = Range(col & startRow + 1)
Else
Set eCell = Range(col & startRow).End(xlDown).Offset(1, 0)
End If
EmptyCell = eCell.Row
End Function

I changed the StartRow to Long.

TheIrishThug wrote:

i'm getting an error with this function now. i tweaked it to a little
and now have:

Function EmptyCell(col As String, startRow As Integer)
Dim eCell As Range
'If Col,startRow is empty return startRow
'If Col,startRow is not empty search down and return row of first empty
cell
If IsEmpty(Range(col & startRow)) Then
Set eCell = Range(col & startRow)
Else
Set eCell = Range(col & startRow).End(xlDown).Offset(1, 0)
End If
EmptyCell = eCell.row
End Function

in this case i am passing col="A" and startRow=3
it works when the function is called with A3 empty, but then when it
should be returning A4 as the next empty cell. i get a
"application-defined or user defined error" and Debug highlights the
line "Set eCell = Range(col & startRow).End(xlDown).Offset(1, 0)"

--
TheIrishThug
------------------------------------------------------------------------
TheIrishThug's Profile: http://www.excelforum.com/member.php...o&userid=29682
View this thread: http://www.excelforum.com/showthread...hreadid=494788


--

Dave Peterson