VBA single cell multiple fonts

elaineconnelly

New Member
Joined
May 21, 2015
Messages
2
I have a spreadsheet with a single cells each containing 4 lines. The lines in the cell are split using Alt+Ent. I want the lines within each cell to be formatted by a different font colour. The top line red, the second line, blue, the third line red and the fourth line green.

I can do this manually by selecting each section of the cell and choosing the font colour but there are approx. 300 cells and I do not want to have to do this for each cell. Is there a way to achieve this by VBA? My data is in cells C3:Z20. The data needs to remain in one cell split into 4 lines - it cannot be entered onto individual rows

I am not a expert on VBA so an help would be great!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi & welcome to MrExcel.
How about
Code:
Sub FontCol()
   Dim Cl As Range
   Dim i As Long, j As Long, x As Long
   For Each Cl In Range("C3:Z20")
      j = 1: i = 1
      For x = 1 To 4
         i = InStr(j, Cl.Value, Chr(10))
         Cl.Characters(j, i).Font.Color = Choose(x, vbRed, vbBlue, vbRed, vbGreen)
         j = i + 1
      Next x
      Next Cl
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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