Color String with VBA

HWL

Active Member
Joined
Dec 1, 2009
Messages
462
I'm trying to color just a segment of a string using VBA. The entire string is generated in VBA but I want a segement to be red.

There should be something in FORMAT perhaps?

test = "This is a test. " & format("test 1 2 3", color#3???)
Thanks for the help
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I'm trying to color just a segment of a string using VBA. The entire string is generated in VBA but I want a segement to be red.
There should be something in FORMAT perhaps?

test = "This is a test. " & format("test 1 2 3", color#3???)
Thanks for the help

You mean in the msgbox or do you want it in a cell?:)

MsgBox does not display rich (formatted) text.
May be you can use Userform to show different text in different colors by using labels etc...:)

All the best
 
Last edited:
Upvote 0
You mean in the msgbox or do you want it in a cell?:)

In a cell.

This is what I have and it works, but sheeesh, really?? I need this mcuh code?

Range("B96") = "TOTALS (Filter to selected configurations) "
cString = " Last ran: " & Format(Now(), "mmm/dd/yyyy @ hh:mm")
i = Len(Cells(96, 2).Value)
Cells(96, 2).Value = Cells(96, 2).Value & "~"
Cells(96, 2).Characters(i + 1).Font.ColorIndex = 1
Cells(96, 2).Value = Cells(96, 2).Value & cString
Cells(96, 2).Characters(i + 2, Len(cString)).Font.ColorIndex = 3
 
Upvote 0
In a cell.
This is what I have and it works, but sheeesh, really?? I need this mcuh code?

Range("B96") = "TOTALS (Filter to selected configurations) "
cString = " Last ran: " & Format(Now(), "mmm/dd/yyyy @ hh:mm")
i = Len(Cells(96, 2).Value)
Cells(96, 2).Value = Cells(96, 2).Value & "~"
Cells(96, 2).Characters(i + 1).Font.ColorIndex = 1
Cells(96, 2).Value = Cells(96, 2).Value & cString
Cells(96, 2).Characters(i + 2, Len(cString)).Font.ColorIndex = 3

yep:), maybe you can do better but i was thinking why is there a need for macro to color font for you...:D
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,223
Members
452,896
Latest member
IGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top