In Excel, it was posible change the font color in part of a cell.
I’ve tried the below code. It’s not working in updated Excel 365 for value (not formula),
Set ce=cells(5,3)
ce.Characters(1, 5).Font.Color = vbBlue
It should change the color in 5 first characters in the cell, but it changes the color of all cell content. Even interactively it’s not working. One select a piece inside a cell, press a color. When exits the cell, it colours all the cell content (in the same way of VBA code)
Why?
Update: It’s my fault. One just can colour part of a text not a number. With text, both VBA or not works OK
After the discussion in comments, Excel accept partial color cell to text content, but not for number content.
So put ABCDEFG
in a active cell. The below code colour the 5 first characters in red. Interactivally it also works.
ActiveCell.Characters(1, 5).Font.Color = vbRed
Now put 1234567
in a active cell. The below code paint all in red. Interactivally the color remains the same before.
ActiveCell.NumberFormat = "@" // Even if you format as text doesn't work
ActiveCell.Characters(1, 5).Font.Color = vbRed
The same code works if you just put a B
before 1234567
…
Tags: excelexcel