Excel教程:替自定义函数设置不定个数的参数

本文为《别怕,Excel VBA其实特别简单(第3版)》随书问题参考答案

以下过程供参考:

Function JoinText(Txt As String, ParamArray list() As Variant) As String

Dim c As Variant, v As Variant

For Each c In list

If TypeName(c) = "Range" Or TypeName(c) = "Variant()" Then

For Each v In c

JoinText = JoinText & v & Txt

Next v

Else

JoinText = JoinText & c & Txt

End If

Next c

JoinText = Left(JoinText, Len(JoinText) - 1)

End Function

AI助手