View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLatham JLatham is offline
external usenet poster
 
Posts: 2,203
Default Finding Next Empty Cell in a Range

Need more information - what last/empty cell are you looking for? Next empty
one in a row or column? Do we need to consider what the current month or day
is?

While we're figuring that out, here's code with 3 separate 'searches' in it,
pick the one you like or wait for another to come along.

Sub FindFirstEmptyCell()
Dim RP As Integer
Dim CP As Integer
Dim seekRange As Range
Dim anyCell As Range
Dim exitFlag As Boolean

Set seekRange = ActiveSheet.Range("B2:AF13") ' 12 x 31
'this just gets the first empty cell it finds
'pretty much a search by row
For Each anyCell In seekRange
If IsEmpty(anyCell) Then
MsgBox "Empty cell at " & anyCell.Address
anyCell.Select
Exit For
End If
Next
'
'this searches left-to-right then down
'results should be same as above
exitFlag = False
For RP = 2 To 13
For CP = Range("B2").Column To Range("AF13").Column
If IsEmpty(Cells(RP, CP)) Then
MsgBox "Empty cell at " & Cells(RP, CP).Address
Cells(RP, CP).Select
exitFlag = True
Exit For
End If
Next
If exitFlag Then
Exit For
End If
Next
'
'this searches down then left-to-right
exitFlag = False
For CP = Range("B2").Column To Range("AF13").Column
For RP = 2 To 13
If IsEmpty(Cells(RP, CP)) Then
MsgBox "Empty cell at " & Cells(RP, CP).Address
exitFlag = True
Cells(RP, CP).Select
Exit For
End If
Next
If exitFlag Then
Exit For
End If
Next

End Sub


"Stilltrader47" wrote:

My worksheet is set-up for 12 month price tracking. The entry range is 12
rows (months) by 31 columns (days). How can I write a macro that will locate
the cursor to the next empty cell in the range? What I am looking for is an
efficient "find" command. I would prefer to execute by ctl-(letter) if
possible.

Thanks for helping.