2

I've created this function:

Public Function getLastCellValue(ByVal row As Integer, ByVal column As String) As String
If (Cells(row, column).Value = "") Then
    getLastCellValue = getLastCellValue(row - 1, column)
Else: getLastCellValue = Cells.Item(row, column).Value
End If
End Function

When I use it in a cell this:

=getLastCellValue(1,"C")  

Excel tells me that the function contains an error and focuses on the second parameter: "C".

I'm going crazy because I do not understand the mistake.

1
  • 2
    Make sure your Excel language is using the comma (,) to separate functions parameters; if your name tells me something about your nationality, I guess you're using an Italian/Spanish system (which means you should separate inputs by semi-column (;) Commented Mar 26, 2015 at 16:01

1 Answer 1

4

Cells(row, column) expects numeric parameter values. If you mean to refer to cell addresses (like, "A1") then it might be simpler to use Range instead.

That said I strongly recommend taking this implementation over to Code Review once you get it to work as expected, ...I'd have several things to point out ;)


Your code works as is on my machine. My bet is on @Matteo's comment

Make sure your Excel language is using the comma (,) to separate functions parameters; if your name tells me something about your nationality, I guess you're using an Italian/Spanish system (which means you should separate inputs by semi-column (;)

Sign up to request clarification or add additional context in comments.

7 Comments

Wrong, it takes the letter as well.
Cells() can use a column's string name. I didn't think it would work either when I saw someone else using it on this board until I tried it. I'm using 2007 for reference.
@MatteoNNZ The IntelliSense calls the parameters [RowIndex] and [ColumnIndex]... damn Microsoft!
Moreover, the function crashes on the beginning, it doesn't enter the code. I guess he should separate values by semi-columns (;) and not commas (,), it should be related to the operating system
The problem was the comma. The correct usage of function require the semicolumn on my Excel 2011 for Mac, Italian version. MatteoNNZ you win!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.