VBA to make the text bold in specific lines in a cell comment box

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
679
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have some simple code below that generates a cell comment based on the values in six cells.
I would like to have the text in the 1st, 3rd and 5th lines in the comment box to be 'bold'. The number of characters in the cells is completely variable.
How would I add to the code below to achieve this? Many thanks.
VBA Code:
Sheet12.Select
    Range("D7").Comment.Text Text:=Range("E6") & Chr(10) & Range("E7") & Chr(10) & Range("E8") & Chr(10) & Range("E9") & Chr(10) & Range("E10") & Chr(10) & Range("E11")
    Range("D7").Comment.Shape.TextFrame.AutoSize = True
Range("D7").Select
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

VBA Code:
Sub bold_comment2()
  Dim n, n1, n2, n3, n4, n5, c
  Sheet12.Select
  n1 = Len([E6])
  n2 = Len([E7])
  n3 = Len([E8])
  n4 = Len([E9])
  n5 = Len([E10])
  c = Chr(10)
  
  With Range("D7")
    .Comment.Text Text:=[E6] & c & [E7] & c & [E8] & c & [E9] & c & [E10] & c & [E11]
    n = Len(.Comment.Text)
    With .Comment.Shape.TextFrame
      .AutoSize = True
      .Characters(1, n).Font.Bold = False
      .Characters(1, n1).Font.Bold = True
      .Characters(n1 + 1 + n2 + 1, n3 + 1).Font.Bold = True
      .Characters(n1 + 1 + n2 + 1 + n3 + 1 + n4 + 1, n5 + 1).Font.Bold = True
    End With
  End With
End Sub
 
Last edited:
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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