[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Last Row in Disjoint Range

Scott

12/20/2006 4:38:00 AM

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

2 Answers

Scott

12/20/2006 4:39:00 AM

0

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

12/20/2006 5:42:00 AM

0

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