Works on cells from A1:Cn, putting the concatenated string in column D of the same row
Sub CellsToString()
Dim WorkRange As Range, _
Cell As Range, _
Ndx As Long, _
RowPtr As Long, _
StartPos As Long, _
WordLength As Long, _
TextColor As Long, _
LastRow As Long, _
FontData As Variant, _
FontDataStr As String, _
NewString As String, _
comma As String
' get the last row in column A
LastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
' loop through the rows
For RowPtr = 1 To LastRow
NewString = ""
FontDataStr = ""
comma = ""
'set the new workrange from column A to C of the current row
Set WorkRange = Range(Cells(RowPtr, "A"), Cells(RowPtr, "C"))
For Each Cell In WorkRange
'copy the font color index and word length
FontDataStr = FontDataStr & comma & Cell.Font.ColorIndex & "," & Len(Cell) + 1
'build the new text string from the cells in the current work range
NewString = NewString & Trim(Cell.Value) & " "
comma = ","
Next Cell
'strip any trailing spaces
Cells(RowPtr, "D").Value = Trim(NewString)
FontData = Split(FontDataStr, ",")
StartPos = 1
'step through each word in the string and apply the colors from the parent cell
For Ndx = 0 To UBound(FontData) - 1 Step 2
WordLength = FontData(Ndx + 1)
TextColor = FontData(Ndx)
Cells(RowPtr, "D").Characters(StartPos, WordLength).Font.ColorIndex = TextColor
'step to the next word in the string
StartPos = StartPos + WordLength
Next Ndx
Next RowPtr
End Sub
Bookmarks