How to put comment in each column (VBA inserted)

tamrob23

Board Regular
Joined
Jun 20, 2006
Messages
203
Good Afternoon,

I have a VBA that needs a small tweek. The VBA that is capturing 4 columns and right now all the comments are going into one column. Basically what ever comments that are in columns A,B,C,D,E need to go into columns F,G,H,I,J. Thank you for taking time to read my thread and have a great day!



Function Comment(ByVal incell As Range) As String
On Error GoTo A:
Comment = incell.Comment.Text
Exit Function
A:
Comment = "Doesn't Exist"
End Function

Sub All_Comments()
Dim myrange As Range, myarray() As String
Set myrange = Range("A1:E100")
For Each cell In myrange
If Not Comment(cell) = "Doesn't Exist" Then
k = k + 1
ReDim Preserve myarray(1 To k) As String
myarray(k) = Comment(cell)
End If
Next

For i = 1 To UBound(myarray)
Range("F1").Offset(i - 1) = myarray(i)
Next i
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hello tamrob23,

This will copy the comments from "A1:E100" to "F1:J100".

Code:
Sub CopyAllComments()


    Dim Cell    As Range
    Dim Rng     As Range
    Dim Text    As String
    
        Set Rng = Worksheets("Sheet1").Range("A1:E100")
        
        For Each Cell In Rng
            On Error Resume Next
                Text = Cell.Comment.Text
                If Err = 0 Then
                    Cell.Offset(0, 5).Comment.Delete
                    Cell.Offset(0, 5).AddComment Text
                End If
            On Error GoTo 0
        Next Cell
        
End Sub
 
Upvote 0
Good Morning,

Thank you for your response, but the VBA you provided moved the comments but they are not extracted from the cell. I would like for the comments to me shown so I can see what the person commented.
 
Upvote 0
Perhaps this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG21Sep35
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Rw [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, t, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("A1:E100")
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not Dn.Comment [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        Dn.Offset(, 5) = Dn.Comment.Text
    [COLOR="Navy"]Else[/COLOR]
        Dn.Offset(, 5).Value = ""
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Yaaaaaay! This is exactly what I need - thank you both so much for taking time out to help with my VBA, have a great day! :-)
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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