ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last Row of Selection (https://www.excelbanter.com/excel-programming/342619-last-row-selection.html)

Bill[_30_]

Last Row of Selection
 
Hello,
Is there a different way of getting the last row of a selection? The first
row is selection.rows(1).row, but I can't get the last row without counting
rows and subtracting one.

lastrow = selection.rows(1).row+selection.rows.count-1

Thanks.

Bill



Bob Phillips[_6_]

Last Row of Selection
 
What is wrong with that way? You do't need rows(1), just

lastrow = selection.row+selection.rows.count-1

An alternative is

LastRow = rng(rng.Count).Row

--
HTH

Bob Phillips

"Bill" wrote in message
link.net...
Hello,
Is there a different way of getting the last row of a selection? The

first
row is selection.rows(1).row, but I can't get the last row without

counting
rows and subtracting one.

lastrow = selection.rows(1).row+selection.rows.count-1

Thanks.

Bill





Mike Fogleman

Last Row of Selection
 
LastRow = Selection.Rows(Selection.Rows.Count).Row

Not much prettier and much more difficult to read.

Mike F
"Bill" wrote in message
link.net...
Hello,
Is there a different way of getting the last row of a selection? The
first row is selection.rows(1).row, but I can't get the last row without
counting rows and subtracting one.

lastrow = selection.rows(1).row+selection.rows.count-1

Thanks.

Bill




Dave Peterson

Last Row of Selection
 
Maybe easier to read:

with selection
LastRow = .Rows(.Rows.Count).Row
end with

and I like:

with selection
LastRow = .cells(.cells.Count).Row
end with

(just to be different!)


Mike Fogleman wrote:

LastRow = Selection.Rows(Selection.Rows.Count).Row

Not much prettier and much more difficult to read.

Mike F
"Bill" wrote in message
link.net...
Hello,
Is there a different way of getting the last row of a selection? The
first row is selection.rows(1).row, but I can't get the last row without
counting rows and subtracting one.

lastrow = selection.rows(1).row+selection.rows.count-1

Thanks.

Bill


--

Dave Peterson


All times are GMT +1. The time now is 02:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com