Need to put comments on autofilter data

danpre

Board Regular
Joined
Aug 29, 2011
Messages
58
Hi,

I Have a data in excel file where i have autofilter Column D.

Need to put comments in Column E for every row.

Please help me with the VBA code as i have tried a lot but not able go through.

Thanks in advance for your help.

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Maybe this?

Gary

Code:
Public Sub Comment_Add()

Dim oCell As Range
Dim oVisible As Range

Dim sCommentText As String

Set oVisible = ActiveSheet.Range("D2:D" & ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible)

For Each oCell In oVisible
    sCommentText = oCell.Text & " : " & Format(Date, "mm/dd/yy")
    oCell.Offset(0, 1).AddComment sCommentText
Next oCell

End Sub


Public Sub Comment_Delete()

Dim oComment As Comment

For Each oComment In ActiveSheet.Comments
    If oComment.Parent.Column = 5 Then oComment.Delete
Next oComment

End Sub
 
Upvote 0
Hi Gary,

Thanks for this code.

What i am asking is that when i filter the data in column D, i need to put some text in Column E on Visible cell

For eg

Column D Column E

D2 PO
D10 PO
D12 PO
D15 PO

I need the code for the above example.
 
Upvote 0
If your autofilter (on column "D") is showing rows 2,10,12 & 15 then then code I posted should put a comment in E2, E10, E12 & E15. The comment text should be the text in column "D" concatenated with a colon and today's date.

If you want to change the text to be just "PO" then change this line:

Code:
sCommentText = oCell.Text & " : " & Format(Date, "mm/dd/yy")

to:

Code:
sCommentText = "PO"

If this is not what you are looking for then I don't know what you're asking for.

Gary
 
Upvote 0
Thanks you so much Gary - Code you provided was for inserting a comment in visible cell.

I needed the code for inserting value in cell.

I corrected that and it is working absolutely fine.

Thanks
 
Upvote 0
Gary,

Could u tell me what the below Code will do

Public Sub Comment_Delete()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Dim oComment As Comment<o:p></o:p>
<o:p> </o:p>
For Each oComment In ActiveSheet.Comments<o:p></o:p>
If oComment.Parent.Column = 5 Then oComment.Delete<o:p></o:p>
Next oComment<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>


Thanks
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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