Hi, Everybody
I want to make my Excel comments occupy as little space as possible, since my worksheet may contain so many.
So, I remove the User Name in all comments if they were created using "Insert Comment"
I also want to remove all spaces represented by vbLf (if user hits Enter).
However, I do not want to delete all vbLf characters, otherwise if a user enters a multi-line comment, it will be made single-lined.
For example if the comment is like this:
Missing Goods:
2 crates Coca Cola
50 kg meat
To phone Johnny to sort out
---
I want the comment to retain its multi-line character, like this:
Missing Goods:
2 crates Coca Cola
50 kg meat
To phone Johnny to sort out
But not like this:
Missing Goods:2 crates Coca Cola50 kg meatTo phone Johnny to sort out
In other words, I would like to delete only those vbLF after the last visible character (out) . This may happen if the user hits Enter after typing his comment.
And, if possible (and if not too complicated to do), to delete the blank lines between the occupied lines.
Here is my existing code:
Thanks for any help.
Leon
NB: RTRIM does not seem to work.
I want to make my Excel comments occupy as little space as possible, since my worksheet may contain so many.
So, I remove the User Name in all comments if they were created using "Insert Comment"
I also want to remove all spaces represented by vbLf (if user hits Enter).
However, I do not want to delete all vbLf characters, otherwise if a user enters a multi-line comment, it will be made single-lined.
For example if the comment is like this:
Missing Goods:
2 crates Coca Cola
50 kg meat
To phone Johnny to sort out
---
I want the comment to retain its multi-line character, like this:
Missing Goods:
2 crates Coca Cola
50 kg meat
To phone Johnny to sort out
But not like this:
Missing Goods:2 crates Coca Cola50 kg meatTo phone Johnny to sort out
In other words, I would like to delete only those vbLF after the last visible character (out) . This may happen if the user hits Enter after typing his comment.
And, if possible (and if not too complicated to do), to delete the blank lines between the occupied lines.
Here is my existing code:
Code:
Sub FormatAllComments()
Dim ws As Worksheet
Dim cmt As Comment
Dim User As String
User = Application.UserName & ":" & vbLf
For Each ws In ActiveWorkbook.Worksheets
For Each cmt In ws.Comments
cmt.Text Text:=Replace(cmt.Text, User, "")
Next cmt
Next ws
End Sub
Thanks for any help.
Leon
NB: RTRIM does not seem to work.
Last edited: