Getting a row number of the last row?

  • Thread starter Thread starter andycharger
  • Start date Start date
A

andycharger

I need to get the row number of my last row in a selection dynamically

How do I get this?


Thanks
 
Hi
if you want the last row in your current selection try
sub foo()
dim rng as range
dim lastrow as long
set rng = selection
lastrow = rng.row+rng.rows.count-1
msgbox lastrow
end sub
 
if rTarget is your range, then
rTarget.Row is the first row,
rTarget.Rows.Count is the number of rows,
thus then last row is
with rTarget
lastrow = .Row + .Rows.Count -1
end with

Patrick Molloy
Microsoft Excel MVP
 
MsgBox Selection.Rows.Count + Selection.Row - 1

Just in case you are looking for the last row of your selection on your workbook.


Regards Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top