ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to detect last row of Selection? (https://www.excelbanter.com/excel-programming/358451-how-detect-last-row-selection.html)

[email protected]

How to detect last row of Selection?
 
I want to have the following loop:

for each cell in Selection
if 'cell in last row in Selection' and 'condition based on cell.value'
then
' process cell in last row
else
' process other cells normally
end if
next

How do I implement the test "cell in last row in Selection"?

Note: Selection is an n-by-m area. So simply testing
"something = last cell of Selection" will not suffice. I need
to recognize any cell in the last row.

Besides, I don't even know how to implement "something =
last cell of Selection". I don't know how to write "something"
(some property of cell?); and I don't know how to write "last
cell of Selection". (Klunk!).

For my edification, I would appreciate it if someone would
tell me how to implement "something = last cell in Selection",
even though that does not address my original problem
above.

Bob Phillips[_6_]

How to detect last row of Selection?
 
lr = rows(selection.row+selection.rows.count-1).row
for each cell in Selection
If cell.row = lr then
' process cell in last row
else
' process other cells normally
end if
next


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

" wrote
in message ...
I want to have the following loop:

for each cell in Selection
if 'cell in last row in Selection' and 'condition based on cell.value'
then
' process cell in last row
else
' process other cells normally
end if
next

How do I implement the test "cell in last row in Selection"?

Note: Selection is an n-by-m area. So simply testing
"something = last cell of Selection" will not suffice. I need
to recognize any cell in the last row.

Besides, I don't even know how to implement "something =
last cell of Selection". I don't know how to write "something"
(some property of cell?); and I don't know how to write "last
cell of Selection". (Klunk!).

For my edification, I would appreciate it if someone would
tell me how to implement "something = last cell in Selection",
even though that does not address my original problem
above.




[email protected]

How to detect last row of Selection?
 
Bob Phillips wrote:
lr = rows(selection.row+selection.rows.count-1).row
for each cell in Selection
If cell.row = lr then
' process cell in last row


Perfect! Thanks.



All times are GMT +1. The time now is 07:12 AM.

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