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

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
575
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
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
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:

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
575
Office Version
  1. 2016
Platform
  1. Windows
That works perfectly!!
Thank you very much indeed :)
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,851
Messages
5,598,452
Members
414,240
Latest member
xnanx

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
Top