I have a problem specifying specific information contained in Excel Cell Comments. I have multiple comments in multiple workbooks that total more than 1M so I am looking for a way that I can apply a routine to clean a workbook, then maybe incorporate it into Workbook_Open() for all of the workbooks.
Example Comment - There could be one blank row or twenty before the first line of text, between any two lines of text or after the last line of text.
**
May 8
June 1
**
I have a small routine that sort of does the trick.
Sub RemoveBlankCommentRows()
Dim c As Comment
For Each c In ActiveSheet.Comments
c.Text Replace(c.Text, "" & Chr(10), " ")
rng.Comment.Shape.TextFrame.AutoSize = True
Next c
End Sub
The only problem with this is that it puts all of the Comment data on a single row as indicated below.
**May 8 June 1**
What I would like is that it returned as indicated below, with or without the blank row between text:
**May 8
June 1**
What I am looking for is a way to distinguish between rows in the Comment that have text and those that have no visible text, but may have a space or several spaces, vbNull, vbNullChar, vbNullString or any other non-printable information. The problem that I am facing is to understand how to determine what line of the Comment is being looked at, or is it the Comment as a whole?
Any help on this would be most appreciated. I have searched everywhere I could and nothing has provided me a way to address the issue without putting all text in a single line.
A very basic approach, but try this:
EDIT:
It will need to be modified a bit to be used in comments. It's been split into 3 like below for reasons particular to my use-case, but for macro-use (as in, for using it on larger areas) I've just created a button on the toolbar that calls cleanSpecialsFromSelection.
For this dataset, I deal with imported data that for reasons pertaining to what I can only assume is character encoding issues contains a lot of non-printable characters, and the results are perfect for me. It's not elegant, though - it relies on the most basic bruteforce approach, and for large datasets it will take time to complete. On my workstations, an 8x3000 selection will take close to 10 seconds.
Here's my code: