ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last Row In Named Range (https://www.excelbanter.com/excel-programming/392586-last-row-named-range.html)

Sprinks

Last Row In Named Range
 
Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks

JLGWhiz

Last Row In Named Range
 
Try this
lastRow = Cells(Rows.Count, NamedRange.Columns(1)).End(xlUp).Row

"Sprinks" wrote:

Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks


Gary Keramidas

Last Row In Named Range
 
try this

Range("test").SpecialCells(xlCellTypeLastCell)

--


Gary


"Sprinks" wrote in message
...
Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks




Gary Keramidas

Last Row In Named Range
 
sorry, you wanted the row, not the cell
i = Range("test").SpecialCells(xlCellTypeLastCell).Row

--


Gary


"Sprinks" wrote in message
...
Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks




Sprinks

Last Row In Named Range
 
JLGWhiz,

Thanks.

"JLGWhiz" wrote:

Try this
lastRow = Cells(Rows.Count, NamedRange.Columns(1)).End(xlUp).Row

"Sprinks" wrote:

Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks


Rick Rothstein \(MVP - VB\)

Last Row In Named Range
 
Can someone tell me how to return the last row in a named range?

LastRow = Range("YourRangeName").Row + Range("YourRangeName").Count - 1

or, more compactly....

With Range("MyRange")
LastRow = .Row + .Count - 1
End With


Rick

Dave Peterson

Last Row In Named Range
 
One more (useful if there are multiple areas in the range):

Option Explicit
Sub testme()

Dim myRng As Range
Set myRng = Worksheets("Sheet1").Range("myname")

With myRng
With .Areas(.Areas.Count)
MsgBox .Rows(.Rows.Count).Row
End With
End With

End Sub




Sprinks wrote:

Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks


--

Dave Peterson

Peter T

Last Row In Named Range
 
Just to add, if not certain the 'last' area contains the 'lowest' row, would
need to loop each area.

Regards,
Peter T

"Dave Peterson" wrote in message
...
One more (useful if there are multiple areas in the range):

Option Explicit
Sub testme()

Dim myRng As Range
Set myRng = Worksheets("Sheet1").Range("myname")

With myRng
With .Areas(.Areas.Count)
MsgBox .Rows(.Rows.Count).Row
End With
End With

End Sub




Sprinks wrote:

Can someone tell me how to return the last row in a named range?

Thank you.
Sprinks


--

Dave Peterson





All times are GMT +1. The time now is 03:42 AM.

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