Substring colouring from Excel VBA: why do some obvious methods not work?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 10:46:57

Assigning the .Value does not magically figure how to append to the existing data. It erases the old data and puts in the new data.

If the characters had colouring, the colour of the first character is used to colour the new string.

If you want the actual appending, same as if you manually used the formula bar in Excel, then append using .Characters:

Dim rngTestString As Range

Set rngTestString = Range("colour_string")

Range("colour_string").Characters(Len(Range("colour_string").Value) + 1).Text = "red "
rngTestString.Characters(1, 4).Font.Color = RGB(255, 0, 0)

Range("colour_string").Characters(Len(Range("colour_string").Value) + 1).Text = "green "
rngTestString.Characters(5, 10).Font.Color = RGB(0, 255, 0)

Range("colour_string").Characters(Len(Range("colour_string").Value) + 1).Text = "blue"
rngTestString.Characters(11, 14).Font.Color = RGB(0, 0, 255)

Formatting (including coloring) substrigns in a range of excel cells with a macro, see the video:

http://youtu.be/O0h6T5Z7HwY

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!