[英]Unable to call VBA function from Excel Worksheet Cell
While trying to use a custom made VBA function from an excel worksheet cell, I get the error: "The formula you typed contains an error" 尝试从excel工作表单元格使用自定义的VBA函数时,出现错误:“您键入的公式包含错误”
However, when I call the same function from VBA, it works alright. 但是,当我从VBA调用相同的函数时,它可以正常工作。
VBA Function: VBA功能:
Public Function R1C1_value(RowIndex As Integer, ColIndex As Integer, Optional WorkSheetName As String) As Variant
Dim ws As WorkSheet
If Trim(WorkSheetName) = "" Then
Set ws = ActiveSheet
Else
Set ws = ActiveWorkbook.Worksheets(WorkSheetName)
End If
R1C1_value = ws.Cells(RowIndex, ColIndex).Value
End Function
VBA Function Call: VBA函数调用:
Sub R1C1_value_test()
Dim res
res = R1C1_value(1, 9, "CVP")
MsgBox "res: " & res
End Sub
Excel Function call Excel函数调用
=R1C1_value(1,9)
The function name is not a Valid name in Excel, even though it is accepted in VBA. 即使在VBA中接受了,该函数名称在Excel中也不是有效名称。 If you change it to xR1C1_value, your function should work.
如果将其更改为xR1C1_value,则函数应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.