×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel - finding the last cell in a collumn in VBA

Excel - finding the last cell in a collumn in VBA

Excel - finding the last cell in a collumn in VBA

(OP)
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

RE: Excel - finding the last cell in a collumn in VBA

This oughtta do it.

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

-handleman, CSWP (The new, easy test)

RE: Excel - finding the last cell in a collumn in VBA

(OP)
ahhhh sneaky - go to the last cell and then seek UP - should have though of that smile

Best regards

Morten

RE: Excel - finding the last cell in a collumn in VBA

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources