« Return to Thread: Custom cell function - how to detect empty cell?

Re: Custom cell function - how to detect empty cell?

by Jan Holst Jensen :: Rate this Message:

Reply to Author | View in Thread

Johnny Rosenberg wrote:

> Function MyFunction(A As Variant) As Variant
>    Dim Something As Variant
>
>    REM Lots of stuff here…
>    MyFunction=Something
> End Function
>
> Using it in a cell:
> =MyFunction(A1)
>
> So A should be the content of the cell A1 in this case. However, if A1
> is empty, A ends up as a double with the value 0. This makes it quite
> impossible to detect wether a cell is empty or not, doesn't it? At
> least I can't find a way to do that.
>  

Hi Johnny.

Hmmm.... that's strange. I could not find a straightforward way either.
Tried IsEmpty() and IsNull() but neither of them worked as expected.
That doesn't mean that there isn't a solution; only that I don't know one.

However, I found this workaround that might be acceptable:

Function MyFunction(A As Variant) As Variant
  if A = "" then
    MyFunction = Null
  else
    MyFunction = "Input is " + A
  end if
End Function

and rewrite the cell function to be

=MYFUNCTION(IF(ISBLANK(A1);"";A1))

Should work if you can live with encoding Null as a blank string.
Thousands of Oracle DBA's, myself included, do that every day even
though it is silly.

Hope this helps.

Cheers
-- Jan Holst Jensen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

 « Return to Thread: Custom cell function - how to detect empty cell?