Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Cell in Column Excel 2007 - Speed Up? 1

Status
Not open for further replies.

plip1978

Technical User
Aug 22, 2007
29
GB
I've always used the following code to find the last cell in a column:

Code:
Public Function LastCellInColumn(sheetOfInterest As String) As Integer

Sheets(sheetOfInterest).Select
Range("A65536").End(xlUp).Select
LastCellInColumn = ActiveCell.Row

End Function

Does anyone have any suggestions on how to speed this up? Or any ideas of a different way to do that that might be faster? I've also moved to Office 2007.

Thank you in advance!
 


hi,

NO SELECT!!!

Also make it GENERAL to other versions with more rows than 65536, and any row greather than 32767 will error as an Integer data type
Code:
Public Function LastCellInColumn(sheetOfInterest As String) As [b]LONG[/b]

   with Sheets(sheetOfInterest)
      LastCellInColumn = .Cells(.rows.count, 1).End(xlUp).row
   end with

End Function

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top