Error when finding the last non-empty cell in a column

D

Davy

Hi guys!
Could do with some help. I have a function to find the
last non-empty cell in a column. But when I call the
function, I get an error - ByRef Argument type mismatch.
The function is as below:

Function Code:

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

My aim is to find the last non -empty cell of column H.
This column has values starting from the 23rd row. So, I
call the function in the "Calculate" event of the
worksheet like this:

Worksheets("Sheet3").Range("j2").Value = LASTINCOLUMN(H)

The column H is of Sheet3. I get the ByRef argument
mismatch at LASTINCOLUMN(H)

What is wrong here? Please help me out!

Thank you!

Davy
 
D

Davy

It doesn't work...

It gives me the row number which is 65536 and not the
value in the last filled cell of the column

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top