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"
However, when I call the same function from VBA, it works alright.
VBA Function:
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:
Sub R1C1_value_test()
Dim res
res = R1C1_value(1, 9, "CVP")
MsgBox "res: " & res
End Sub
Excel Function call
=R1C1_value(1,9)