Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
J, Good question. And thanks for your continued review of my issue. The
current date is relevant, here's why. I will not be populating every cell in the range with a price value. Days will be skipped, meaning cells in the range will be left empty. Below is a brief example to help illustrate. April (Col) R S T U V W 13 4/17/10 4/18/10 4/19/10 4/20/10 4/21/10 4/22/10 14 5.00 4.75 See that for April, the 19th, 20th and 21st do not have a price value entered. So when the macro is run on 4/22, it should really be looking for the next empty cell in the range equla to or approximate to the current date. Like Row 13 above, dates will be pre-populated for all 12 months. I hope this better explains what I am looking for. Thanks Tom "JLatham" wrote: 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
finding first empty cell | Excel Programming | |||
Finding next empty empty cell in a range of columns | Excel Programming | |||
Finding next available empty cell in a row | Excel Programming | |||
Finding first (end of range) empty cell | Excel Programming | |||
Finding the next empty cell. | Excel Programming |