0

How to write UDF in Visual Basic for Applications that can work with structured references like this:

=UDF([Colomn1])

or this:

=UDF(if(len([Colomn1])>1,[Colomn1]))

Any ideas?

@Rory, this function work with range, but not work with reference to column. Result values are repeated.

Function udff(sRange As Range) As Variant
    Dim valueArr As Variant
    valueArr = sRange.Value
    ReDim resArr(LBound(valueArr, 1) To UBound(valueArr, 1), LBound(valueArr, 2) To UBound(valueArr, 2))
    For i = LBound(valueArr, 1) To UBound(valueArr, 1)
        For j = LBound(valueArr, 2) To UBound(valueArr, 2)
            resArr(i, j) = valueArr(i, j) & "!"
        Next j
    Next i
    udff = resArr
End Function
Community
  • 1
  • 1

1 Answers1

1

Your syntax appears wrong. [Colomn1] should be [@Colomn1] (and possibly spelled correctly).

Function udf(rng As Range)
    udf = rng * 2
End Function

colomn1

Do not confuse the ability to use associative full column references with true worksheet range references (e.g. A1 or A:A) with ListObject (aka structured) table references.

colomn2