Given the BigConcat function is basically a "Join" function with delimiter,
I don't know how useful this variation on the last code I posted will prove
to be, but it allows you to inject text strings into the list. For example,
you can do this (in addition to using non-contiguous ranges in the list)...
=BigConcat("; ",A1:A10,"Some Text in the middle of the list",B2:H2,J3:M9)
Anyway, modifying the code to allow for this was relatively easy to do, so I
did it.<g> Here is the code which adds this feature into the mix...
Function BigConcat(Delimiter As String, ParamArray Data()) As String
Dim X As Long, Z As Long, IR As Range
For Z = LBound(Data) To UBound(Data)
If TypeName(Data(Z)) = "Range" Then
For X = Data(Z)(1).Row To Data(Z)(1).Row + Data(Z).Rows.Count - 1
Set IR = Intersect(Data(Z), Rows(X))
If IR.Count = 1 Then
BigConcat = BigConcat & IR.Value & Delimiter
Else
BigConcat = BigConcat & Join(WorksheetFunction.Transpose( _
WorksheetFunction.Transpose(Intersect( _
Data(Z), Rows(X)))), Delimiter) & Delimiter
End If
Next
Else
BigConcat = BigConcat & Data(Z) & Delimiter
End If
Next
Do While InStr(BigConcat, Delimiter & Delimiter)
BigConcat = Replace(BigConcat, Delimiter & Delimiter, Delimiter)
Loop
BigConcat = Left(BigConcat, Len(BigConcat) - Len(Delimiter))
If InStr(BigConcat, Delimiter) = 1 Then
BigConcat = Mid(BigConcat, Len(Delimiter) + 1)
End If
End Function
--
Rick (MVP - Excel)
Okay, you may find this version of the function more flexible to use. The
first version I posted *requires* a contiguous range of cells; this version
will work with multiple, non-contiguous ranges; for example, something like
this...
=BigConcat("; ",A1:A10,B2:H2,J3:M9)
The only problem (if this is even a problem) is that the Delimiter is no
longer optional and there is no default for it (and it has been moved to the
first argument position in order to allow an unspecified number of ranges to
be passed into the function as a comma delimit list). Okay, here is the
function code...
Function BigConcat(Delimiter As String, ParamArray Data()) As String
Dim X As Long, Z As Long, IR As Range
For Z = LBound(Data) To UBound(Data)
For X = Data(Z)(1).Row To Data(Z)(1).Row + Data(Z).Rows.Count - 1
Set IR = Intersect(Data(Z), Rows(X))
If IR.Count = 1 Then
BigConcat = BigConcat & IR.Value & Delimiter
Else
BigConcat = BigConcat & Join(WorksheetFunction.Transpose( _
WorksheetFunction.Transpose(Intersect( _
Data(Z), Rows(X)))), Delimiter) & Delimiter
End If
Next
Next
Do While InStr(BigConcat, Delimiter & Delimiter)
BigConcat = Replace(BigConcat, Delimiter & Delimiter, Delimiter)
Loop
BigConcat = Left(BigConcat, Len(BigConcat) - Len(Delimiter))
If InStr(BigConcat, Delimiter) = 1 Then
BigConcat = Mid(BigConcat, Len(Delimiter) + 1)
End If
End Function
--
Rick (MVP - Excel)
A minor oversight on my part. Use this macro instead...
Function BigConcat(Data As Range, Optional Delimiter As String) As String
Dim X As Long, IR As Range
For X = Data(1).Row To Data(1).Row + Data.Rows.Count - 1
Set IR = Intersect(Data, Rows(X))
If IR.Count = 1 Then
BigConcat = BigConcat & IR.Value & Delimiter
Else
BigConcat = BigConcat & Join(WorksheetFunction.Transpose( _
WorksheetFunction.Transpose(Intersect( _
Data, Rows(X)))), Delimiter) & Delimiter
End If
Next
Do While InStr(BigConcat, Delimiter & Delimiter)
BigConcat = Replace(BigConcat, Delimiter & Delimiter, Delimiter)
Loop
BigConcat = Left(BigConcat, Len(BigConcat) - Len(Delimiter))
If InStr(BigConcat, Delimiter) = 1 Then
BigConcat = Mid(BigConcat, Len(Delimiter) + 1)
End If
End Function