Function
TextUnion(delimiter
As
String
, ignore_empty
As
Boolean
,
ParamArray
arr()
As
Variant
)
As
String
Application.Volatile
If
IsMissing(arr())
Then
TextUnion =
""
:
Exit
Function
Dim
Rg
As
Range, Tmp
As
Variant
For
a = LBound(arr())
To
UBound(arr())
If
Not
IsMissing(arr(a))
Then
Select
Case
TypeName(arr(a))
Case
"Range"
For
Each
Rg
In
arr(a)
If
Len(Rg.Value) > 0
Or
(Len(Rg.Value) = 0
And
Not
ignore_empty)
Then
TextUnion = TextUnion & delimiter & Rg.Value
Next
Case
"Variant()"
For
Each
Tmp
In
arr(a)
If
Len(Tmp) > 0
Or
(Len(Tmp) = 0
And
Not
ignore_empty)
Then
TextUnion = TextUnion & delimiter & Tmp
Next
Case
Else
If
Len(arr(a)) > 0
Or
(Len(arr(a)) = 0
And
Not
ignore_empty)
Then
TextUnion = TextUnion & delimiter & arr(a)
End
Select
End
If
Next
TextUnion = Mid(TextUnion, Len(delimiter) + 1)
End
Function