Thread: End(xlDown)
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default End(xlDown)

Hi

Another option, if you for some reason need to use xlDown:

If Range("A2")="" then
LastRow=2
Else
LastRow=Range("A1").end(xlDown).row
End if

Hopes this helps.
....
Per

"Normek" skrev i meddelelsen
...
Hi Fellow Excel users,
Has anyone come across the following problem before and do they have an
answer?

End(xlDown) is a useful shortcut method, however in a macro similar to
this
below, if the cells below contains only one record or no records, then the
count is 1048575 in Excel 2007 or 50000 in excel 2003.

Sub CntCells()
ans = Range(Range("A1"), Range("A1").End(xlDown)).Count
MsgBox ans
End Sub

Similarly
Range("A1").End(xlDown).Offset(1, 0).Select
fails because Range("A1").End(xlDown).Select will select the last row

Has anyone any thoughts or alternatives?

Thanks in advance