简体   繁体   English

Excel函数语法调用错误

[英]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" . Excel告诉我该函数包含一个错误,并专注于第二个参数: "C"

I'm going crazy because I do not understand the mistake. 我快要疯了,因为我不明白这个错误。

Cells(row, column) expects numeric parameter values . Cells(row, column)需要数字参数值 If you mean to refer to cell addresses (like, "A1") then it might be simpler to use Range instead. 如果要引用单元格地址(例如“ A1”),则使用Range可能更简单。

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 ;) 话虽如此,我强烈建议您将该实现付诸实践后,将其实施到Code Review中 ,...我有几点要指出;)


Your code works as is on my machine. 您的代码工作我的机器上。 My bet is on @Matteo's comment 我的赌注是@Matteo的评论

Make sure your Excel language is using the comma (,) to separate functions parameters; 确保您的Excel语言使用逗号(,)分隔函数参数; 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 (;) 如果您的名字告诉我有关您的国籍的信息,则可能是您使用的是意大利语/西班牙语系统(这意味着您应使用半列(;)分隔输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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