Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.Cells(xlDown) with one item in list

Status
Not open for further replies.

hsummer

Technical User
Dec 10, 2001
13
US
I have a function that looks at a list of numbers, and I want to use .Cells(xlDown) to get to the bottom of the range.

When there is only one item, the xlDown goes to the bottom of the sheet. Then if I do a "For each c in ..." it takes a while.

What is an easy way to prevent that?

Thanks,
Harold
 
Assign to a variable and test
dim lastRow as long
lastRow = activecell.end(xldown).row
If lastRow = 65536 then
'You only have 1 item
else
'You have more than 1 item
end if

HTH Rgds
~Geoff~
 
This should get you started

It assumes data will be in A1

Code:
Sub marine()
Dim strCell As String
If IsEmpty(Range("A1").Offset(1, 0)) Then
    strCell = Range("A1").Address
Else: strCell = Range("A1").End(xlDown).Address
End If
MsgBox "Last Cell is " & strCell

End Sub

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top