Passing Labels Cells in Calc Basic

I want to pass labelled cells to a custom function. However nothing I can find seems to solve the problem.

The simplest example of my problem is

  Cell b2 is label M with a value of 1.11
 -----------------------------------------------
 My Custom Function is 
       Function Echoval(A as Single) 
                 Echoval = A
      End Function 
 ---------------------------------

=Echoval(b2) returns 1.11

=Echoval(‘M’) crashes.

Did your term labelled Cells refers from Option →Tools→Options→Calc→Calculate→[x]Automatically find Column and Rowlabels ??

yes ? - so how should your poor basic-UDF determine the relative Position of the “Calling-Cell” , much less find the right Cell relativ to some “Label” in first Row|Column?

For that Purpose you have to write an AddInn-Extension Doc or tuturial or example or another example

IHMO: this silly Label-option is somehow Errorprone, I wouldn’t use it in any case.

================================================

Maybe your ECHOVAL is only for Example, but it is a bad Example, because you have to write in Calc only ='M' for the same return.

I suppose you are talking about “Automatic Addressing” and thus about an automatically named range when writing “Labels Cells”.

You will know that “our” BASIC always passes parameters by value. In this case, however, it won’t pass a scalar value but a 2-dimensional array, indexes starting with 1 and row index first. The array may well consist of only one element. You have to access an element, however, by indexing.

If your named range actually has only one element you may use this code:

Function GetTopLeftElement(pCellContent)
GetTopLeftElement = pCellContent(1,1)
End Function

@karolus is right, of course. The example is useless. It may be enhanced, however.