I wrote the following function to concatenate a range of cells. It works fine, but I don't understand -- if a range is 1 row & multiple columns it will go to the final "Else" and will be transposed two times. I arrived at this via trial and error and was pleasantly surprised it worked, but still don't understand why it is necessary to transpose twice. Can anyone please shed any light? Thanks!
Code:
Public Function CONCATENATERANGE(ByVal rng As Range, Optional sDelimiter As String) As String
Dim Arr As Variant
If rng.Cells.Count = 1 Then
ReDim Arr(1 To 1, 1 To 1)
Arr(1, 1) = rng.Value2
ElseIf rng.Rows.Count > 1 Then
Arr = rng.Value2
Else
Arr = Application.Transpose(Application.Index(rng.Value2, 1, 0))
End If
Arr = Application.Transpose(Arr)
CONCATENATERANGE = Join(Arr, sDelimiter)
End Function