View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default How do I find the next blank cell in a range?

You can loop backwards through the columns:

Option Explicit
Sub testme01()

Dim FirstEmptyCell As Range
Dim wks As Worksheet
Dim myRng As Range
Dim iCol As Long

Set wks = Worksheets("sheet1")

With wks
Set myRng = .Range("a1:B20")
End With

With myRng
For iCol = .Columns.Count To 1 Step -1
Set FirstEmptyCell = Nothing
On Error Resume Next
Set FirstEmptyCell _
= .Columns(iCol).Cells.SpecialCells(xlCellTypeBlanks ).Cells(1)
On Error GoTo 0

If FirstEmptyCell Is Nothing Then
'keep looking
Else
Exit For
End If
Next iCol
End With

If FirstEmptyCell Is Nothing Then
MsgBox "No empty cells!"
Else
MsgBox FirstEmptyCell.Address
End If

End Sub

Be aware that .specialcells() only looks at the used range. I'm not sure if
that's a problem for you.


EazyCure wrote:

First blank would be B1. (Left to right, then top to bottom).


--

Dave Peterson