尝试从excel工作表单元格使用自定义的VBA函数时,出现错误:“您键入的公式包含错误”
但是,当我从VBA调用相同的函数时,它可以正常工作。
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函数调用:
Sub R1C1_value_test()
Dim res
res = R1C1_value(1, 9, "CVP")
MsgBox "res: " & res
End Sub
Excel函数调用
=R1C1_value(1,9)
即使在VBA中接受了,该函数名称在Excel中也不是有效名称。如果将其更改为xR1C1_value,则您的函数应该可以使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句