ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to find the last line? (https://www.excelbanter.com/excel-programming/364995-how-find-last-line.html)

italo

how to find the last line?
 
how can i find the number of the last line of a sheet??
urgent, please!

PCLIVE

how to find the last line?
 
By last line, do you mean the last line that contains data? Press Ctrl+End.


"italo" wrote in message
...
how can i find the number of the last line of a sheet??
urgent, please!




Jim Thomlinson

how to find the last line?
 
This will give you the row number of the last row in column A.

msgbox cells(rows.count, "A").end(xlup).row
--
HTH...

Jim Thomlinson


"italo" wrote:

how can i find the number of the last line of a sheet??
urgent, please!


Chris

how to find the last line?
 
Hi italo,

You could try: ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row

or use the following function:

Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%

' Error-handling is here in case there is not any
' data in the worksheet

On Error Resume Next

With ws

' Find the last real row

LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).row

' Find the last real column

LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

End With

' Finally, initialize a Range object variable for
' the last populated row.

Set LastCell = ws.Cells(LastRow&, LastCol%)

End Function

To use the above function:

LastCell(Worksheets("Your Worksheet Name")).row
or
LastCell(ActiveSheet).row

Hope this helps,

Chris

"italo" wrote in message
...
how can i find the number of the last line of a sheet??
urgent, please!




Kent

how to find the last line?
 
Here you go...

iLastRow = UBound(ActiveSheet.UsedRange.Value2, 1) +
ActiveSheet.UsedRange.Row - 1

iLastColumn = UBound(ActiveSheet.UsedRange.Value2, 2) +
ActiveSheet.UsedRange.Column - 1

-Kent


italo wrote:
how can i find the number of the last line of a sheet??
urgent, please!




All times are GMT +1. The time now is 01:49 PM.

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