1

That's a tricky one: I got 3 different numbers extracted by three different formulas in the same cell (as the image below).

enter image description here

Is there a way to color those numbers with different styles (i.e. first blue, second green, third bold)?

Thank you!

Community
  • 1
  • 1
Doppia L
  • 141
  • 3
  • 8
  • 1
    Try this: http://stackoverflow.com/questions/7618121/excel-vba-change-color-of-certain-characters-in-a-cell and http://stackoverflow.com/questions/7759962/excel-change-font-color-for-specific-char-in-a-cell-range – zedfoxus Mar 11 '15 at 14:11
  • 1
    If there's a formula in the cell, no. – Rory Mar 11 '15 at 14:15
  • Ok, let's suppose I don't have the formula inside the cell. – Doppia L Mar 11 '15 at 14:36

1 Answers1

2

Here is what you need, all you have to do is swap the Range("A3") with the one you have =]

Sub Color_Part_of_Cell()

Dim cont1       As Integer
Dim cont2       As Integer

cont1 = WorksheetFunction.Search("%", Range("A3"))

cont2 = Len(Mid(Range("A3"), WorksheetFunction.Search("-", Range("A3"), 1), _
            WorksheetFunction.Search("%", Range("A3"), _
            WorksheetFunction.Search("-", Range("A3"), 1)))) - cont1 - 2

With Range("A3")
.Characters(1, cont1).Font.Color = RGB(0, 0, 255)
.Characters(cont1 + 3, cont2).Font.Color = RGB(0, 255, 0)
.Characters(cont1 + cont2 + 6, 10).Font.Bold = true
End With

End Sub
Ygor Yansz
  • 176
  • 1
  • 4
  • 12