Here's Harlan Grove's custom function, which concatenates values within a range or array...
As you can see, it first tests for a range and then for an array. Since the IsArray function returns True for both a range and array, is there any reason why the code cannot be re-written as follows?
Code:
Function AConcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
AConcat = AConcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
AConcat = AConcat & y & sep
Next y
Else
AConcat = AConcat & a & sep
End If
AConcat = Left(AConcat, Len(AConcat) - Len(sep))
End Function
As you can see, it first tests for a range and then for an array. Since the IsArray function returns True for both a range and array, is there any reason why the code cannot be re-written as follows?
Code:
Function AConcat(a As Variant, Optional sep As String = "") As String
Dim y As Variant
If IsArray(a) Then
For Each y In a
AConcat = AConcat & y & sep
Next y
Else
AConcat = AConcat & a & sep
End If
AConcat = Left(AConcat, Len(AConcat) - Len(sep))
End Function