Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font color for a part of text in cell

Tags:

excel

vba

I have cells which will contain the below value

"Image not allowed|png"

I want to change the color of |png alone or whatever comes after "|"

Now i am trying to change the font color using the below code

Cells(4,2).Font.Color = RGB(255, 50, 25)

It will change the entire cells font color, Is it possible to change only the selected text color(|png) using VBA?

like image 668
Vignesh Subramanian Avatar asked Jun 01 '15 07:06

Vignesh Subramanian


1 Answers

Yes this is possible. A good way to explore the Excel object model is to use the macro recorder to record a macro where you manually carry out the manipulation you're interested in.

In this case, you can use:

Cell.Characters(Start:=1, Length:=5).Font

to set font properties of a substring in a cell.

like image 130
Joe Avatar answered Sep 17 '22 13:09

Joe