Populate massage box from a VLOOKUP

eric7753

New Member
Joined
Dec 30, 2009
Messages
9
I am using Excel 2010 and Windows 7

I have some code that works well to populate a message box from a VLOOKUP. The code will do the lookup on a cell, for simplicity sake say C2, and insert a comment on C2. I would like to offset the comment placement by two columns, so the VLOOKUP would reference C2 and place the comment in A2. Any assistance would be appreciated.

Code:
Function AddCommentFromVlookup(myCommentCell As Range, _
                               myTable As Range, _
                               myColumn As Long, _
                               myBoolean As Boolean) As Variant
    Application.Volatile True
    Dim res As Variant
    Dim myLookupCell As Range
    Dim myStr As String
    With myCommentCell
        res = Application.Match(.Value, myTable.Columns(1), myBoolean)
        If IsError(res) Then
            myStr = "Not found"
        Else
            Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
            myStr = myLookupCell.Text
        End If
        If .Comment Is Nothing Then
            
        Else
            .Comment.Delete
        End If
        .AddComment Text:=myStr
    End With
    AddCommentFromVlookup = ""
End Function
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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