I\'ve been building some interesting visualizations that rely on VBA code\'s ability to set different colours for substrings in Excel. For a cell containing a string the syn
Formatting (including coloring) substrigns in a range of excel cells with a macro, see the video:
http://youtu.be/O0h6T5Z7HwY
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)