简体   繁体   中英

Custom function, that works with structured references in Excel tables

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

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

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

第1列

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

第2列

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM