Useful functions

Discussion regarding the spreadsheet functionality of Bet Angel.
Post Reply
User avatar
ODPaul82
Posts: 808
Joined: Sun May 08, 2011 6:32 am

Hi guys,

Having been prompted by a PM here are a few useful functions which should work in either 2003 or 2007 excel.

The first one, lngLastRow, will return the row number which is last used on the workbook. It should work from Excel 2010 all the way back to Excel 97 (haven't tested on Excel 95, not that anyone should be using it!!!)

These all test the first column (A), if anyone would like me to show them how to test other columns then just let me know.

Public Function lngLastRow(ByRef objSheet As Excel.Worksheet) As Long

With objSheet
lngLastRow = .Rows(.Rows.Count).End(xlUp).Row
End With

End Function

If you wanted to actually return the range then you could use the following:

Public Function rngLastRow(ByRef objSheet As Excel.Worksheet) As Range

With objSheet
Set rngLastRow = .Rows(.Rows.Count).End(xlUp)
End With

End Function

Regards
Paul.
Post Reply

Return to “Bet Angel - Spreadsheet / Excel chat”