ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to find the last row and column (https://www.excelbanter.com/excel-programming/303190-how-find-last-row-column.html)

WayneM[_2_]

How to find the last row and column
 
Is there a simple way to find the last row and column of
an Excel sheet? I am using VB6 to read data from Excel
and need to know if there is a property or method that
will provide this info.

Thanks in advance,

WayneM

Ron de Bruin

How to find the last row and column
 
Hi Wayne

With this two functions you can do this

Sub test()
MsgBox LastRow(ActiveSheet)
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


And this one

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"WayneM" wrote in message ...
Is there a simple way to find the last row and column of
an Excel sheet? I am using VB6 to read data from Excel
and need to know if there is a property or method that
will provide this info.

Thanks in advance,

WayneM





All times are GMT +1. The time now is 02:07 AM.

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