Last Row in Disjoint Range

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

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
 
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,

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.
 
Back
Top