I'm trying to use my own VBA function in an Excel sheet with a return value and the same function manipulates a cell on the same or on an other sheet, but the result is #VALUE!
A minimal working example (Office Prof Plus 2010, 32-bit):
Function abc() As Integer
Dim i%
i = 0
Sheet1.Cells(1, 2).Value = 2
abc = i
End Function
When I execute Debug.Print abc
it obviously writes a 2
to the cell B2
and the printed result is 0
. What I want to do now is =abc()
in cell A1
on Sheet1
, but I only get #VALUE!
. Btw, it doesn't work either if Application.EnableEvents
and Application.Calculation
is disabled resp. set to manual.
Two questions: Why? And any idea how to resolve? Thx.