-2

I have an Excel sheet as below,

enter image description here

and I would like to give color change and bold change for specific positions that defined another columns like below.

enter image description here

Position1 : 1,2,3,10
Position2 : 5,6,7,8

So Change blue color for position 1,2,3,10. And Change Red Color for position 5,6,7,8

Does anyone has good idea to make a function?

Cœur
  • 37,241
  • 25
  • 195
  • 267
clear.choi
  • 835
  • 2
  • 6
  • 19
  • [Here](http://stackoverflow.com/questions/7618121/change-color-of-certain-characters-in-a-cell) is a good place to start. – Scott Craner Sep 11 '15 at 17:51

1 Answers1

2

Here is a small sub that will help you get started. Assuming your position1 value is in A2, position2 value is in B2 and Example is in C2.

You can modify it to cover bigger range.

Sub test()

    Dim i As Long
    Dim text As String
    Dim p1, p2 As Variant

    p1 = Split(Range("A2").Value, ",")
    p2 = Split(Range("B2").Value, ",")
    text = Range("C2").Value

    For i = LBound(p1) To UBound(p1)
        Cells(2, 3).Characters(p1(i), 1).Font.Color = vbBlue
    Next

    For i = LBound(p2) To UBound(p2)
        Cells(2, 3).Characters(p2(i), 1).Font.Color = vbRed
    Next

End Sub
ManishChristian
  • 3,759
  • 3
  • 22
  • 50