How to pass cell address like A1 without double quota into macro function

how to pass cell address like A1 without double quota into macro function. for example
A1 in formula =UDF(A1) directly passed instead dereferenced as Text String

I think it is not possible to use that notation without quotes.
You can use numerical position notation instead:
("A1") = (0,0)

1 Like

Hallo


function double_udf( source as variant )
	double_udf = source * 2
end function

udf

1 Like

(This is about a solution using Basic with Option VBAsupport 1.)

If you create a module with Option VBAsupport 1 you can pass an argument which can be interpreted by the UDF as a reference - if it is one only, of course. (You can also access dereferenced data).
Interested in the reference you should test the parameter, say p1, with If IsObject(p1) Then ....
You may also work with an "ErrorExit" as my example does using the target label fail:.
See example:
disask111343_passReferenceToCalcUDF.ods (14.5 KB)

1 Like

In addition to @Lupp’ s answer, a function for independent research with an arbitrary number of arguments:

Option Explicit
Option VbaSupport 1

' Returns number of arguments and argument types.
' For cell ranges, also returns the range address.
Function ArgType(ParamArray args)
  Dim res As String, txt as String, i As Long
  If Ubound(args)<Lbound(args) Then
    ArgType="No arguments"
    Exit Function
  End If
    
  res="Number of arguments: " &  (Ubound(args) + 1)
  For i=Lbound(args) To Ubound(args)
    txt=TypeName(args(i))
    If txt="Range" Then 
      txt=txt & " " & args(i).CellRange.AbsoluteName
    End If  
    res=res & Chr(10) & i & ": " & txt
  Next i
  
  ArgType=res
End Function

Example:

=ARGTYPE(A1; 2)

shows

Number of arguments: 2
0: Range $Sheet1.$A$1
1: Double