简体   繁体   中英

excel function syntax calling error

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.

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 (;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM