VBA-Bold font in comments box

Kenn

Board Regular
Joined
Sep 23, 2009
Messages
195
Hi.
I am currently using a formula to populate a cell comment box based on a look-up results of the box contents.


Code:
Option Explicit
Function AddCommentFromVlookup(myCommentCell As Range, _
                               myTable As Range, _
                               myColumn As Long, _
                               myBoolean As Boolean) As Variant
    Application.Volatile True
    Dim res As Variant 'could be an error
    Dim myLookupCell As Range
    Dim myStr As String
    With myCommentCell
        res = Application.Match(.Value, myTable.Columns(1), myBoolean)
        If IsError(res) Then
            myStr = "Not found"
        Else
            Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
            myStr = myLookupCell.Text
        End If
        If .Comment Is Nothing Then
            'do nothing
        Else
            .Comment.Delete
        End If
        .AddComment Text:=myStr
    End With
    AddCommentFromVlookup = "" 'the value in the cell with the function
    
    'USE THIS CODE TO ACTIVATE THE FORMULA
        '=AddCommentFromVlookup(A1,A:B,2,FALSE)
End Function


Once this is done I am then running a VBA script to format the comment box.


Code:
Sub ChgAllComments()
    Dim Cell As Range
        Dim UserN As String
        Dim commt As String
        Dim myBolds
        Dim i As Long
        
        
    For Each Cell In Cells.SpecialCells(xlCellTypeComments)
        With Cell.Comment.Shape.TextFrame
            .Characters.Font.Name = "Tahoma"
            .Characters.Font.Size = 8
            .Characters.Font.FontStyle = "Regular"
            .AutoSize = True            
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        
        End With
Application.DisplayCommentIndicator = xlCommentIndicatorOnly

    Next
End Sub


Problem i have is that I need to format first 4 lines of the comment box to be bold (this will always be 4 lines in all comment boxes)

Any suggestions would be greatly appreciated.
Kenn
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this

Code:
Sub ChgAllComments()
    Application.ScreenUpdating = False
    Dim Cell As Range
    Dim UserN As String
    Dim commt As String
    Dim myBolds
    Dim i As Long
        
    For Each Cell In Cells.SpecialCells(xlCellTypeComments)
        pos = 1
        For i = 1 To 4
            nl = InStr(pos, Cell.Comment.Text, Chr(10))
            If nl = 0 Then
                nl = Len(Cell.Comment.Text)
                Exit For
            End If
            pos = nl + 1
        Next
        With Cell.Comment.Shape.TextFrame
            .Characters.Font.Name = "Tahoma"
            .Characters.Font.Size = 8
            .Characters.Font.FontStyle = "Regular"
            .AutoSize = True
            .Characters(1, nl).Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .ReadingOrder = xlContext
        End With
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    Next
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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