ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro code to find last record in excel (https://www.excelbanter.com/excel-programming/381171-macro-code-find-last-record-excel.html)

Raj

macro code to find last record in excel
 
Hi
Please send me an example code to get the last record number in a worksheet

Martin Fishlock

macro code to find last record in excel
 
Raj:

What do you mean by the last record number.

Excel is not a database is it a spreadsheet.

If you mean the last row in the speadsheet then:

activesheet.cells.rows.count

if you mean the last row with some entry on it then:

activesheet.usedrange.row + activesheet.usedrange.rows.count - 1

--

Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Raj" wrote:

Hi
Please send me an example code to get the last record number in a worksheet


Bob Phillips

macro code to find last record in excel
 
MsgBVox Cells(LastRow,LastCol).Value





'-----------------------------------------------------------------
Function LastRow() As Long
'-----------------------------------------------------------------
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End Function

'-----------------------------------------------------------------
Function LastCol() As Long
'-----------------------------------------------------------------
LastCol = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End Function




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Raj" wrote in message
...
Hi
Please send me an example code to get the last record number in a

worksheet




All times are GMT +1. The time now is 02:30 PM.

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