Remove final blank lines in comment box

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
771
Office Version
  1. 365
Platform
  1. Windows
I am using the code below to create comment boxes with text that appears in certain columns on the worksheet. There is intentionally one blank line inserted between each comment in the comment box. It works perfectly. However, it also leaves two blank lines after the last comment. Is there a way to eliminate the final two blank lines so that the final comment is the last line in the comment box? Thanks!

Code:
Sub AddCommentBox(rowNumber)  

Dim c As Range
Dim commentText As String
Dim heading As String
Dim i As Integer
Dim x As String

heading = "FEEDBACK" & vbCrLf & vbCrLf

For i = 80 + columnReturn To 90 + columnReturn

x = IIf((Cells(rowNumber + rowReturn, i)) = "", "", vbCrLf)

    If IsNumeric(Cells(rowNumber + rowReturn, i)) Then
        commentText = commentText & Format(Cells(rowNumber + rowReturn, i), "#,###")
    Else
        commentText = commentText & Cells(rowNumber + rowReturn, i)
    End If
    commentText = commentText & x & x
    Next i

Set c = Cells(rowNumber + rowReturn, 16 + columnReturn)

c.AddComment
c.Comment.Text Text:=heading & commentText
c.Comment.Shape.TextFrame.AutoSize = True

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
After this line:
VBA Code:
Set c = Cells(rowNumber + rowReturn, 16 + columnReturn)

Add this line:
VBA Code:
If commentText <> "" Then commentText = Left(commentText, Len(commentText) - 3)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,882
Messages
6,175,166
Members
452,615
Latest member
bogeys2birdies

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