That still assumes you have correctly guessed which column is going to be the "longest"... See also Colin's remark. I hadn't even thought of that onebut that's why you would use:
- no version issues.Code:Cells(rows.Count, 1).End(xlUp)
Public Function LastRowInSheet(wks As Worksheet) As Long
' Returns the number of the last row with data anywhere in it
LastRowInSheet = 1
On Error Resume Next
With wks.UsedRange
LastRowInSheet = .Cells.Find(what:="*", after:=.Cells(1), _
SearchOrder:=1, _
SearchDirection:=2).Row
End With
End Function
Sub foo()
MsgBox udfLastCell(ActiveSheet).Row
End Sub
Function udfLastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%
LastRow = 1: LastCol = 1
'// Error-handling is here in case there is not any
'// data in the worksheet
On Error Resume Next
With ws
'// Find the real last row
LastRow = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
'// Find the real last column
LastCol = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With
Set udfLastCell = ws.Cells(LastRow, LastCol)
End Function
And this begs the question, will future versions of Excel support the probability functions needed to run Infinite Improbability Drives?Measure in Earth standard days, obviously the rotational period of any other place would knacker a watch as Arthur Dent found out
And now I am forced to ask... Do you carry that sledgehammer around in your pocket?
Aaaannnnd now I feel dirty. Besides I was looking at rorya's pant's..... I mean uhm, never mind.Ahem, that ain't a sledgehammer, and my eyes are up here, mister...
gdammit Archibald. I was sippin' my coffee when I read that. Damñed near got coffee both up my nose and on the keyboard.What pants?