Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default first empty cell


starting at A3 i need to return the first cell that is empty.

i tried:
Row = 3
While IsEmpty("A" & Row) = False
Row = Row + 1
Wend

but i get a overflow error that selects "row=row+1"

i found the following code somewhere else, but this won't work. the
sheet i'm using is setup as a list. so the last line of the list says
"total." since the following looks from the bottom up, it does not go
to possible empty cells above that.

code:
Sub FindLastCell()
Dim LastCell As Range
With ActiveSheet
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
If IsEmpty(LastCell) Then
'do nothing
Else
Set LastCell = LastCell.Offset(1, 0)
End If
End With
MsgBox LastCell.Row
End Sub


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default first empty cell

Try:

Sub EmptyCell()
Dim eCell As Range
If IsEmpty(Range("A4")) Then
Set eCell = Range("A4")
Else
Set eCell = Range("A3").End(xlDown).Offset(1, 0)
End If
MsgBox eCell.Address
End Sub

Hope this helps
Rowan

TheIrishThug wrote:
starting at A3 i need to return the first cell that is empty.

i tried:
Row = 3
While IsEmpty("A" & Row) = False
Row = Row + 1
Wend

but i get a overflow error that selects "row=row+1"

i found the following code somewhere else, but this won't work. the
sheet i'm using is setup as a list. so the last line of the list says
"total." since the following looks from the bottom up, it does not go
to possible empty cells above that.

code:
Sub FindLastCell()
Dim LastCell As Range
With ActiveSheet
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
If IsEmpty(LastCell) Then
'do nothing
Else
Set LastCell = LastCell.Offset(1, 0)
End If
End With
MsgBox LastCell.Row
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default first empty cell


very nice, thank you


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default first empty cell

You're welcome

TheIrishThug wrote:
very nice, thank you


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default first empty cell


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



  #6   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When is a cell empty and how do I empty it. C Brandt Excel Discussion (Misc queries) 5 August 13th 07 05:37 PM
Leaving an empty cell empty GRL Excel Discussion (Misc queries) 4 April 22nd 06 05:47 PM
why a reference to an empty cell is not considered empty Nicoscot Excel Discussion (Misc queries) 10 March 10th 06 05:36 AM
Empty cell and a the empty String JE McGimpsey Excel Programming 0 September 13th 04 04:12 PM
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? SROSENYC Excel Programming 1 August 5th 03 04:34 AM


All times are GMT +1. The time now is 04:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"