Value of a user-defined function

advertisements

I have an User Defined Function in Excel 2010 VBA.

In a cell A1, I call that function: =myfunction() and the returned value (as Integer) is showed correctly in the A1 cell.

My concern is how can I obtain the value of A1 cell from other function in VBA. I want that MyOtherFunction() obtain the number of A1.

The cell A1 has =MyFunction()

function MyFunction() as integer
   ......
   MyFunction = 99
End function

I see correctly the value 99 in A1.

function MyOtherFunction()
   dim valor as integer
   valor =  Workbooks("xxx.xlsm").Sheets("yyy").Range("A1").Value
End function

In that function the variable valor return 0 instead 99.


Function MyOtherFunction(Rng As Range) As Whatever
    '~~> Rest of the code
End Function

In a worksheet as a UDF

=MyOtherFunction(A1)

In VBA

Sub Sample()
    Dim Ret
    Ret = MyOtherFunction(ThisWorkbook.Sheets("Sheet1").Range("A1"))
End Sub