does anyone know a simple way to concatenate a range of
cells, e.g. A1:CA1, without typing 100 "&"s.
Since everyone else has provided an array concatenation udf, why not mine too?
Function mcat(ParamArray s()) As String
'Copyright (C) 2002, Harlan Grove
'This is free software. It's use in derivative works is covered
'under the terms of the Free Software Foundation's GPL. See
'
http://www.gnu.org/copyleft/gpl.html
'------------------------------------
'string concatenation analog to SUM
Dim r As Range, x As Variant, y As Variant
For Each x In s
If TypeOf x Is Range Then
For Each r In x.Cells
mcat = mcat & r.Value
Next r
ElseIf IsArray(x) Then
For Each y In x
mcat = mcat & IIf(IsArray(y), mcat(y), y)
Next y
Else
mcat = mcat & x
End If
Next x
End Function
This takes a variable number of arguments, handles ranges, arrays (including
arrays of arrays if called by other VBA procedures), and single (scalar) values.