Would like to include formatting with my coloring of concatenated cells

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
Ok, I have a sub-routine below that works well in coloring a concatenated target cell the same as the color in multiple source cells. How can I include the source cells formatting as well (i.e., whether the source is bolded, italicized, underlined, etc . . ) in the concatenated cell?

Sub ConcatAndColorParts(target As Range, source As Range, Optional delim As String = " ")
Dim cell As Range, v As Variant, i As Integer

target.Value2 = ConcatRangeChars(source, delim)
v = ""
i = 1
For Each cell In source
With cell
target.Characters(i, Len(.Value2)).Font.Color = .Font.Color
i = i + Len(.Value2) + Len(delim)
End With
Next cell
With Selection
.HorizontalAlignment = xlJustify
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = True
.ReadingOrder = xlContext
.MergeCells = False
End With
Rows(target.Row).EntireRow.AutoFit
With ActiveCell
.Value = Left(.Value, Len(.Value) - 1)
End With
ActiveCell.Offset(1, 0).Select
End Sub

Function ConcatRangeChars(charRange As Range, Optional delim As String = " ") As String
Dim v As String, cell As Range

Application.Volatile False

v = ""
For Each cell In charRange
v = v & cell.Text & delim
Next cell
v = Left(v, Len(v) - Len(delim))

ConcatRangeChars = v
End Function

Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,748
Messages
5,855,439
Members
431,732
Latest member
albertdi827

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top