MrPatterns
MrPatterns

Reputation: 4434

Is it possible to do multiple colored text within an Excel cell?

I have string strInfo, which contains "Employee John Maybach".

How do I make the "Employee" part black text, and the "John Maybach" part red?

The "Employee" part will always remain constant, but the employee's name part will change such that it may be a 2-part name (John Doe), or a 3-part name (John Allen Doe), or just a first name (John).

I want the word "Employee" to be always black, but the rest of the text in the cell, the name part, to be red. Is this possible?

Upvotes: 6

Views: 9008

Answers (1)

assylias
assylias

Reputation: 328735

The macro recorder is your friend:

Dim fixedLength As Long
fixedLength = Len("Employee")
ActiveCell.FormulaR1C1 = "Employee Some Employee"
With ActiveCell.Characters(Start:=fixedLength + 2, Length:=Len(ActiveCell) - fixedLength - 1).Font
    .Color = vbRed
End With

Upvotes: 7

Related Questions