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.
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