Thread: Macros in excel
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Ramage Dave Ramage is offline
external usenet poster
 
Posts: 44
Default Macros in excel

You can use the End property of a range- this is the same as holding down
Ctrl + [Down/Up Arrow]. If you are sure that there is one continuous range of
non-blank cells in the column then it is more reliable to start at the bottom
of the column and search up:

Sub GetBlankCell_1()
Dim lRow As Long, lColToCheck As Long

'''find first empty row in column A
lColToCheck = 1 'Column A
'check last row in this column
If Cells(Rows.Count, lColToCheck).Formula "" Then
'assume no empty cells in this column
lRow = Rows.Count
Else
lRow = Cells(Rows.Count, lColToCheck).End(xlUp).Row + 1
End If

'now do something with this value
Cells(lRow, lColToCheck).Select
End Sub

If it is better to start at the top of the column and search down, then use
this:

Sub GetBlankCell_1()
Dim lRow As Long, lColToCheck As Long

'''find first empty row in column A
lColToCheck = 1 'Column A
'check last row in this column
If Cells(Rows.Count, lColToCheck).Formula "" Then
'assume no empty cells in this column
lRow = Rows.Count
Else
lRow = Cells(Rows.Count, lColToCheck).End(xlUp).Row + 1
End If

'now do something with this value
Cells(lRow, lColToCheck).Select
End Sub

In both examples, if the column is full then the last cell in the column is
selected.

Cheers,
Dave


"plugger" wrote:

how to find first empty cell in a selected column ie A12:A20 with a macro