Thread: [Solved] lastincolumn function
View Single Post
 
Old 01-29-2010, 01:36 PM
rdcsfd rdcsfd is offline Windows 7 Office 2007
Novice
 
Join Date: Jan 2010
Posts: 3
rdcsfd is on a distinguished road
Default lastincolumn function

lastincolumn is a walkenbach function that returns the value for the last filled cell in a column. works well and is very fast.

Function LASTINCOLUMN(rngInput As Range)
Dim WorkRange As Range
Dim i As Integer, CellCount As Integer
Application.Volatile
Set WorkRange = rngInput.Columns(1).EntireColumn
Set WorkRange = Intersect(WorkRange.Parent.UsedRange, WorkRange)
CellCount = WorkRange.Count
For i = CellCount To 1 Step -1
If Not IsEmpty(WorkRange(i)) Then
LASTINCOLUMN = WorkRange(i).Value
Exit Function
End If
Next i
End Function

the following function, lastinrange, is a modification of lastincolumn to return the location/range of the last filled cell in a column, necessary to use with offset function. But, it is excruciatingly slow. does anyone know why?

Function LastInRange(InputRange As Range)
Dim CellCount As Long
Dim i As Long
CellCount = InputRange.Count
For i = CellCount To 1 Step -1
If Not IsEmpty(InputRange(i)) And IsNumeric(InputRange(i)) Then
Set LastInRange = InputRange(i)
Exit Function
End If
Next i
LastInRange = ""
End Function
Reply With Quote