VBA Concatenate and retain color format

Bgreen83

New Member
Joined
Oct 3, 2019
Messages
6
Hello Fellow Users,

I need help concatenating two columns and retaining the color format located in column B. Please see the snapshot below. Can someone help me with the VBA code? Thank you!

Column A (A1:A200)
Name

Column B (B1:B200).....Column B text color: RGB (47, 117, 181)
Lname

Column C (C1:C200)
Name - Lname
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Sub t()
Dim i As Long
For i = 1 To 200
With ActiveSheet
.Cells(i, 3) = .Cells(i, 1).Value & "-" & .Cells(i, 2).Value
End With
Next
ActiveSheet.Range("C1:C200").Interior.Color = RGB(472, 117, 181)
End Sub
 
Upvote 0
Hi JLGWhiz,
Thank you for your reply! This is very helpful. What I would like to do is keep the 'Column A' text font as Black RGB(0, 0, 0) and 'Column B' text font as RGB(472, 117, 181). What would this change look like?
 
Upvote 0
Sorry, I misread the OP. I assume you mean that in column C you want the font to retain the color of their source. See it this is better.
Code:
Sub t()
Dim i As Long
    For i = 1 To 200
        With ActiveSheet
            .Cells(i, 3) = .Cells(i, 1).Value & "-" & .Cells(i, 2).Value
            .Cells(i, 3).Characters(InStr(.Cells(i, 3).Value, "-") + 1, _
             Len(.Cells(i, 3).Value) - InStr(.Cells(i, 3).Value, "-")).Font.Color = RGB(472, 117, 181)
        End With
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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
Back
Top