I need to fill a cell with the result of a user function. If the result of the function is different from zero, the cell should be simply filled with the result of the function; so far so good.
But if the result is zero I want the cell to be empty.
So I wrote this user defined function:
Function MyTestFunction(n As Integer) As Integer
Dim result As Integer
result = n * 2
If result = 0 Then
MyTestFunction = Empty
Else
MyTestFunction = result
End If
End Function
The function has no real purpose, it's just for investigating this issue.
The Excel sheet is like follows:
Cells A1 to A3 is just typed in data, cells B1 to B3 contain:
- B1:
=MyTestFunction(A1)
- B2:
=MyTestFunction(A2)
- B3:
=MyTestFunction(A3)
Now why does cell B3 display 0
instead of being empty ?