ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Format some, not all, text in a comment (https://www.excelbanter.com/excel-programming/437240-format-some-not-all-text-comment.html)

Jock

Format some, not all, text in a comment
 
Using "Target.Offset(, 1).AddComment", I can add a comment to a cell which
will display values from UserForm 1 TextBox2 and TextBox3.
In between these two values in the comment, I have placed a " v " (to
indicate one party against the other).
I would like to format this "v" to bold and red.
As both TextBox Values are unknown lengths, how can I achieve this?
Many thanks
--
Traa Dy Liooar

Jock

Jacob Skaria

Format some, not all, text in a comment
 
Try the below..

Sub Macro1()

Dim objCom As Comment, strText1 As String, strText2 As String

strText1 = "Man"
strText2 = "Animal"

Set objCom = Range("A1").AddComment(strText1 & " v " & strText2)

With objCom.Shape.TextFrame
.Characters(Len(strText1) + 2, 1).Font.ColorIndex = 3
.Characters(Len(strText1) + 2, 1).Font.Bold = True
End With

End Sub

--
Jacob


"Jock" wrote:

Using "Target.Offset(, 1).AddComment", I can add a comment to a cell which
will display values from UserForm 1 TextBox2 and TextBox3.
In between these two values in the comment, I have placed a " v " (to
indicate one party against the other).
I would like to format this "v" to bold and red.
As both TextBox Values are unknown lengths, how can I achieve this?
Many thanks
--
Traa Dy Liooar

Jock


Jacob Skaria

Format some, not all, text in a comment
 
Another way is to use Instr()

Dim objCom As Comment, strComment As String
strComment = "Man v Animal"
Set objCom = Target.Offset(, 1).AddComment(strComment)
With objCom.Shape.TextFrame
.Characters(InStr(1, objCom.Text, " v ", vbTextCompare),
3).Font.ColorIndex = 3
.Characters(InStr(1, objCom.Text, " v ", vbTextCompare), 3).Font.Bold = True
End With

--
Jacob


"Jock" wrote:

Using "Target.Offset(, 1).AddComment", I can add a comment to a cell which
will display values from UserForm 1 TextBox2 and TextBox3.
In between these two values in the comment, I have placed a " v " (to
indicate one party against the other).
I would like to format this "v" to bold and red.
As both TextBox Values are unknown lengths, how can I achieve this?
Many thanks
--
Traa Dy Liooar

Jock



All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com