By Colo

Without Separators

Function Chain(myRange As Range) As String
 Dim c As Range
 For Each c In myRange.Cells
  Chain = Chain & c.Value
 Next c
End Function

With Separators

Function Chain(myRange As Range, Optional sSep As String = "") As String
 Dim c As Range
 For Each c In myRange.Cells
  Chain = Chain & sSep & c.Value
 Next c
 Chain = Mid(Chain, 2)
End Function

Multiple Ranges

Function Chain(TargetCells As Range, Optional Separator As Variant) As String
 ' Mid(Chain, Len(Separator) + 1) suggested by Joerd, ( was Mid(Chain, 2) )
 Dim c As Range
 If IsMissing(Separator) Then
  For Each c In TargetCells.Cells
   Chain = Chain & c.Value
  Next c
 Else
  For Each c In TargetCells.Cells
   Chain = Chain & Separator & c.Value
  Next c
 Chain = Mid(Chain, Len(Separator) + 1)
 End If
End Function



© Copyright andrewsexceltips.net All Rights Reserved.