ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last Row in Disjoint Range (https://www.excelbanter.com/excel-programming/379754-last-row-disjoint-range.html)

Scott

Last Row in Disjoint Range
 
Hi,

Title pretty much says it all.

How do I find the last row in a disjoint range assuming they're all in
the same object? ie. What do I put in here?

Function GetLastRow (Target as Range) as Long
'Target range is not contiguous

GetLastRow = ?
End Function

Thanks,
Scott


Scott

Last Row in Disjoint Range
 
Hmmm, maybe answered my own question. Would appreciate verification
that nothing bad can happen with this (ie. can you end up with the last
item not being in the last row)?

GetLastRow = Target(Target.Count).Row

Thanks,
Scott

Scott wrote:
Hi,

Title pretty much says it all.

How do I find the last row in a disjoint range assuming they're all in
the same object? ie. What do I put in here?

Function GetLastRow (Target as Range) as Long
'Target range is not contiguous

GetLastRow = ?
End Function

Thanks,
Scott



Martin Fishlock

Last Row in Disjoint Range
 
Scott,

Try it and it won't work on multiple areas.

The only way I can get it to work is as follows:

Sub SubGetLastRow()
MsgBox CStr(GetLastRow(Selection))
End Sub

Function GetLastRow(Target As Range) As String
'Target range is not contiguous
Dim rCell As Range
Dim lRow As Long
For Each rCell In Target
If rCell.Row lRow Then lRow = rCell.Row
Next rCell
GetLastRow = lRow

End Function

It's not very effecient but it works.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Scott" wrote:

Hmmm, maybe answered my own question. Would appreciate verification
that nothing bad can happen with this (ie. can you end up with the last
item not being in the last row)?

GetLastRow = Target(Target.Count).Row

Thanks,
Scott

Scott wrote:
Hi,

Title pretty much says it all.

How do I find the last row in a disjoint range assuming they're all in
the same object? ie. What do I put in here?

Function GetLastRow (Target as Range) as Long
'Target range is not contiguous

GetLastRow = ?
End Function

Thanks,
Scott





All times are GMT +1. The time now is 11:21 AM.

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