Insert comment into cell

E

Elton Law

Dear Expert,
Have 2 columns ....
Column A is name
Column B is type
I want the content in column B to put as comments in respective column A.

For example,
Name Type
Elton PT
Jasmine PT
Tony FT, 10
Kammi PT, 12

Would like to put PT as comment in cell A2 (Elton)
Would like to put PT as comment in cell A3 (Jasmine)
Would like to put FT, 10 as comment in cell A4 (Tony)

It can certainly be done manually ... by copy, right click the cell, choose
insert comment .....repeat and repeat ...
I have 1000 cells to be done.
Hope VBA can automate the task. Thanks
 
M

Mike H

Hi,

Try this macro

Sub No_Comment()
Dim c As Range
Dim LastRow As Long
Set Sht = Sheets("Sheet1") ' change to suit
LastRow = Sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sht.Range("A2:A" & LastRow)
For Each c In MyRange
With c
If .Comment Is Nothing Then
.AddComment c.Offset(, 1).Value
End If
End With
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
E

Elton Law

Hi Mike,
It does not work.

Stop here .... debug ... highlight this part.
Can you help?

..AddComment c.Offset(, 1).Value
Thanks
 
D

Dave Peterson

Mike's code worked ok for me (well, after I dimmed a couple more variables,
<vbg>).

So...

Did you change his code?
Is your worksheet protected?
Do you have errors in those adjacent cells?

If you changed his code, post your new version.
If your worksheet is protected, unprotect it first (either in code or manually)
and try again.
If you have errors in those adjacent cells, try using:
..AddComment c.Offset(, 1).Text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top