2

我创建了这个函数:

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

当我在单元格中使用它时:

=getLastCellValue(1,"C")  

Excel 告诉我该函数包含错误并关注第二个参数:"C".

我要疯了,因为我不明白这个错误。

4

1 回答 1

4

Cells(row, column)需要数字参数值。如果您的意思是指单元格地址(例如“A1”),那么使用它可能更简单Range

也就是说,一旦你让它按预期工作,我强烈建议将这个实现交给代码审查,......我有几件事要指出;)


您的代码我的机器上工作正常。我的赌注是@Matteo 的评论

确保您的 Excel 语言使用逗号 (,) 分隔函数参数;如果你的名字告诉我你的国籍,我猜你使用的是意大利/西班牙系统(这意味着你应该用半列(;)分隔输入

于 2015-03-26T15:58:26.803 回答