Hi,
I did not have any luck searching so figured I would ask. A co-worker has a workbook with many sheets. Many of the cells have comments. It has been decided it would be better if the information from the cell comment were entered as text in the cell to the right (omitting the name of the originator of the comment). I thought I had seen code for this type of thing but cannot find it now. It would be safer to have the code process one column at a time (as selected by the user). I tried recording a macro but that did not work well ;-). Any chance I could get some help on this one?
Print Cell comments in next column as text entry
-
- 3StarLounger
- Posts: 233
- Joined: 10 Feb 2010, 19:17
Print Cell comments in next column as text entry
Chuck Reimer
(I'm from the Government and I'm here to help) ;-)
(I'm from the Government and I'm here to help) ;-)
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Print Cell comments in next column as text entry
Here is a macro you can use:
The code strips away the first line of each comment on the assumption that it is the author name. If the author name (or the line feed after it) has been removed, the result will not be correct.
Code: Select all
Sub ListComments()
Dim oCell As Range
Dim rng As Range
Dim strComment As String
Dim intPos As Integer
' Avoid error if there are no comments
On Error GoTo ExitHere
' Limit to one column
Set rng = Selection.Columns(1)
' Insert cells to the right
rng.Offset(0, 1).Insert Shift:=xlShiftToRight
' Loop through cells with comments
For Each oCell In rng.SpecialCells(xlCellTypeComments)
' Get comment
strComment = oCell.Comment.Text
' Strip away first line
intPos = InStr(strComment, vbLf)
If intPos > 0 Then
strComment = Mid(strComment, intPos + 1)
End If
' Enter in cell to the right
oCell.Offset(0, 1) = strComment
Next oCell
ExitHere:
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 233
- Joined: 10 Feb 2010, 19:17
Re: Print Cell comments in next column as text entry
Thanks Hans, I will test it out and run it by the Engineer that requested it.
Chuck Reimer
(I'm from the Government and I'm here to help) ;-)
(I'm from the Government and I'm here to help) ;-)
-
- 3StarLounger
- Posts: 233
- Joined: 10 Feb 2010, 19:17
Re: Print Cell comments in next column as text entry
Hans,
I tested it and was surprised. The part of the code that says Insert cells to the right, did not seem to work, hence the comments write over the data in the cell to the right. This is not a major problem as I will tell them to make sure they insert a column to the right of the cells with comments.
Thanks so much.
I tested it and was surprised. The part of the code that says Insert cells to the right, did not seem to work, hence the comments write over the data in the cell to the right. This is not a major problem as I will tell them to make sure they insert a column to the right of the cells with comments.
Thanks so much.
Chuck Reimer
(I'm from the Government and I'm here to help) ;-)
(I'm from the Government and I'm here to help) ;-)
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Print Cell comments in next column as text entry
You are supposed to select the cells with the comments. The code will insert blank cells to the right of (the first column of) the selection.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 233
- Joined: 10 Feb 2010, 19:17
Re: Print Cell comments in next column as text entry
Thanks Hans
You made one Engineer very HAPPY.
You made one Engineer very HAPPY.
Chuck Reimer
(I'm from the Government and I'm here to help) ;-)
(I'm from the Government and I'm here to help) ;-)