ok, so i have some cells, which have a comment applied to each, based on specific criteria, here’s the code i have so far….
Sub Insert_Value_Comments() Dim CellRange As Range Set CellRange = Range("Holding_Cost") Dim Val As Long For Each cell In CellRange If cell.Value > 0 Then cell.ClearComments cell.AddComment Text:="Current Value: " & Chr(10) & " £ " & cell.Value + cell.Offset(0, 1).Value If cell.Value + cell.Offset(0, 1).Value >= cell.Value Then ' set Val variable to either 5 (blue) or 3 (red) Val = 5 Else Val = 3 End If With cell.Comment.Shape .AutoShapeType = msoShapeRoundedRectangle ' set comment shape .Line.Weight = 1.5 ' increase line thickness around comment .TextFrame.Characters.Font.Name = "Tahoma" .TextFrame.Characters.Font.Size = 9 .TextFrame.Characters(1, 14).Font.Bold = True ' set top line of text to bold .TextFrame.Characters(15, Len(cell.Comment.Text)).Font.ColorIndex = Val ' set 2nd line of text to red/blue .Fill.ForeColor.RGB = RGB(135, 220, 128) ' set background colour, Can also use ".SchemeColor = ??" instead of RGB .TextFrame.AutoSize = True ' resize comment box End With Else cell.ClearComments End If Next cell ' Ensure comments are set to display only indicators Application.DisplayCommentIndicator = xlCommentIndicatorOnly End Sub
now this works, exactly as i expected, it will produce the comment as per the code, and it will look like this
Current Value:
£ 3456.25
and when the value hits a minus figure, it switches to red text, however, it does 2 things that i’d like to alter
1. the negative values, show in red, but with no “-” symbol
2. it messes with the number formats, for example £ 1350.50 will come out formatted as “£ 1350.5” ….. i don’t want to lose the trailing 0, and i’d also like to format the numerical value as £ 1,350,50 if possible.
Anyone have any idea how i can manipulate the formatting, or do i need to manipulate it whilst building the comment text ?