How to find last selected row in excel worksheet

Is there a way to figure out what is the last row in a selection on a worksheet?  Maybe someone can point me in the right direction.  

So if i select rows 1 to 13, in code i want to figure out that 13 is the last row in the selection.

Is there a way?

LVL 13
LucasMS Dynamics DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in VB code ?

selection.row     tells you the first row selected

selection.rows.count   tells you how many are selected


selection.row + selection.rows.count -1  

tells you the last row

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Calvin BrineCommented:
Another option.

Dim R as String

r = range("A65535").end(xlup).row

Will return the last used row in Column A.

LucasMS Dynamics DeveloperAuthor Commented:
Exactly what i was looking for THANKS A MILLION!
Jeroen RosinkSoftware testing consultantCommented:
here some other macro's to find the last anything:

'Find the last used cell, before a blank in a Column:
Sub LastCellBeforeBlankInColumn()
   MsgBox Range("A1").End(xlDown).Address
End Sub

'Find the very last used cell in a Column:
Sub LastCellInColumn()
   MsgBox Range("A65536").End(xlUp).Address
End Sub

'Find the last cell, before a blank in a Row:
Sub LastCellBeforeBlankInRow()
    MsgBox Range("A1").End(xlToRight).Address
End Sub

'Find the very last used cell in a Row:
Sub LastCellInRow()
   MsgBox Range("IV1").End(xlToLeft).Address
End Sub

'Find the very last used cell on a Worksheet:
Sub Demo()
   MsgBox Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Address
End Sub

Sub NumberOfUsedRowsInA()
MsgBox RowsA = Cells(Rows.Count, 1).End(xlUp).Row
End Sub

or for the last row number in the selection

Sub LastRowInSelection()
For Each cel In Selection
    LastRow = cel.Row
Next cel
MsgBox LastRow
End Sub


Jeroen RosinkSoftware testing consultantCommented:
keep in mind that the line: selection.rows.count shows only the number of rows which are selected. not the number of the last row which is selected

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.