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 cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - finding the last cell in a collumn in VBA 1

Status
Not open for further replies.

MortenA

Chemical
Joined
Aug 20, 2001
Messages
2,998
Location
DK
If you have a collumn where there exists an unknown number of "blanks" short of stepping through each row is there a smart way of finding the last cell with data?

Selection.End(xlDown).Activate

will find the "next" empty cell but if you dont know if thats the "last" blank?

In my case there will only be one blank - but still just testing the next cell seems a bit too "easy" and is not fool proof - if there could be two blanks and the more data.

Best regards

Morten
 
This oughtta do it.

Cells(65536, Selection.Column).End(xlUp).Activate

-handleman, CSWP (The new, easy test)
 
ahhhh sneaky - go to the last cell and then seek UP - should have though of that :-)

Best regards

Morten
 
A small tweak
Cells(rows.count, Selection.Column).End(xlUp).Activate

has the very small advantage that you don't have to remember that 65000 number and it will be forward compatible with future versions excel that may be Avogadro's number of rows.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top