VBA Question - Populate Comment with Cell Value from Formula

bc4240

Board Regular
Joined
Aug 4, 2009
Messages
134
Office Version
  1. 365
Platform
  1. Windows
I'm in need of some code that will put the values in the cells of Column D into a comment of the associated name in Column B. I do not have room in the worksheet cells to put this info and thought including the information as a comment with the person's name might be a solution.

Column D values will reference a table like that of Columns H and I on another worksheet. Here the Column D formula that I'm using to get the corresponding values for the names in Column B

IFNA(INDEX($H$4:$I$11,MATCH(B4,$H$4:$H$11,0),2),"")

does not reference another sheet because it is just and example.

It would be great if the VBA code would activate when any name in Column B is changed, thus causing the comment in that changed cell in Column B to clear and then re-populate with the new values generated in Column D.

This way the order of the names is irrelevant.

Thanks in advance for any help you all can provide.

<tbody>
</tbody>


IFNA(INDEX($H$4:$I$11,MATCH(B4,$H$4:$H$11,0),2),"")
Tommy Leerocker, pam,John Holmeshappy, sally, disney, jonny
Billy Mayesqvc, sale, make money, hawkTimmy JonesTJ, golfer, walker
John Holmeshappy, sally, disney, jonnyBilly Mayesqvc, sale, make money, hawk
Tommy Leerocker, pam,George Jonescountry, western, guitar
Brad Badbb, bad, arm wrestlerTommy Leerocker, pam,
Arnold Swartzget to the chopper, I'll be backBrad Badbb, bad, arm wrestler
Timmy JonesTJ, golfer, walkerArnold Swartzget to the chopper, I'll be back
Danny O'DayIrish, river dancerDanny O'DayIrish, river dancer

<tbody>
</tbody>

IFNA(INDEX($H$4:$I$11,MATCH(B4,$H$4:$H$11,0),2),"")

<tbody>
</tbody>
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
bc4240,

You might consider the following...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then GoTo errHandler:
If Not Intersect(Columns("B:B"), Target) Is Nothing Then
    On Error GoTo errHandler
    Application.EnableEvents = False
    Dim ws2 As Worksheet
    Dim rng As Range, found As Range
    Dim s As String
    
    Set ws2 = Sheets("Sheet2")
    Set rng = ws2.Range("H1", ws2.Cells(Rows.Count, "I").End(xlUp))
    With Target
        .ClearComments
        Set found = rng.Columns(1).Find(What:=.Value, After:=rng.Cells(1, 1), LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
        If Not found Is Nothing And found.Value <> "" Then
            s = found.Offset(0, 1).Value
            .AddComment.Text s
        End If
    End With
End If
errHandler:
    Application.EnableEvents = True
    If Err.Number <> 91 And Err.Number <> 0 Then MsgBox "An error occured at Row " & Target.Row & ", " & Target.Value & _
        vbCrLf & Err.Number & ", " & Err.Description
End Sub

The code should be pasted into the Sheet Module that contains the comments.

Cheers,

tonyyy
 
Upvote 0
Solution
Tonyyy,

Thanks so much worked like a charm!!! Nice to have talented people like yourself out there helping.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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