[VBA] How to add Comments to Table column using text from another column

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
437
Office Version
  1. 365
Platform
  1. Windows
Hi,

I want to add comments to Table column using text from another column in the same row.

I've been trying to modify the VLookup-based solution (which only works if the values in the column to apply comments to {Col1] are unique).
VBA Code:
Dim lookRange As Range 'Range to use for comments

'Define ranges
Set commentRange = Range("Table10[Col1]")
Set lookRange = Range("Table10[[Col1]:[Col3]]")

'loop through and add comment
For Each c In commentRange
    With c
        .ClearComments
        .AddComment
        .Comment.Text Text:=CStr(WorksheetFunction.VLookup(c.Value, lookRange, 3, False))
    End With
Next c

End Sub

Should I be using listobjects along the lines of For c = 1 To tbl.ListRows.Count?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This seems to work, by simply specifying the number of columns offset from the active cell (in my case 2):

VBA Code:
Sub AddNotesfromColumn()
Dim commentRange As Range 'Range to add comments to
Dim c As Range
Set commentRange = Range("Table10[Col1]") 'Define range

'loop through and add comment
For Each c In commentRange
 With c
 .ClearComments
 .AddComment
 .Comment.Text Text:=c.Offset(0, 2).Value
End With
Next c

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

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