提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
注册账户
x

or

如何查看和返回匹配的值与单元格评论?

当您应用Vlookup函数返回匹配值时,它只会提取没有格式的值,例如填充颜色,字体或注释等。但是,有时您可能需要查找并返回匹配的值(包括注释)以及得到下面的截图结果。 你怎么能在Excel中解决这个问题?

Vlookup并使用VBA代码返回与单元格注释匹配的值


Vlookup并使用VBA代码返回与单元格注释匹配的值


下面的VBA代码可能会帮助您查看并返回匹配的值及其评论,请按照以下步骤操作:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2。 点击 插页 > 模块,然后复制并粘贴以下代码 模块 窗口。

VBA代码:Vlookup并用单元格注释返回匹配值:

Function VlookupComment(LookVal As Variant, FTable As Range, FColumn As Long, FType As Long) As Variant
'Updateby Extendoffice
    Application.Volatile
    Dim xRet As Variant 'could be an error
    Dim xCell As Range
    xRet = Application.Match(LookVal, FTable.Columns(1), FType)
    If IsError(xRet) Then
        VlookupComment = "Not Found"
    Else
        Set xCell = FTable.Columns(FColumn).Cells(1)(xRet)
        VlookupComment = xCell.Value
        With Application.Caller
            If Not .Comment Is Nothing Then
                .Comment.Delete
            End If
            If Not xCell.Comment Is Nothing Then
                .AddComment xCell.Comment.Text
            End If
        End With
    End If
End Function

3。 然后保存代码并关闭代码窗口,输入以下公式: = vlookupcomment(H2,A2:C10,3,FALSE) 进入空白单元格以查找结果,然后按 输入 键,匹配的值以及注释立即返回,请参见截图:

注意:在上面的公式中, H2 是要返回其相应值的查找值, A2:C10 是您要使用的数据表,数字 3 是包含要返回的匹配值的列号。



推荐的Excel生产力工具

Kutools for Excel帮助您提前完成工作,并从人群中脱颖而出

  • 超过300强大的高级功能,专为1500工作场景设计,通过70%提高生产力,让您有更多时间照顾家庭和享受生活。
  • 不再需要记忆公式和VBA代码,从现在起让你的大脑休息一下。
  • 成为3分钟的Excel专家,复杂和重复的操作可以在几秒钟内完成,
  • 每天减少成千上万的键盘和鼠标操作,现在告别职业病。
  • 110,000高效人才和300 +世界知名公司的选择。
  • 60-day full功能免费试用。 60天退款保证。 2多年的免费升级和支持。

将选项卡式浏览和编辑带到Microsoft Office,远比浏览器的选项卡强大

  • Office选项卡专为Word,Excel,PowerPoint和其他Office应用程序设计:Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Derek Carl · 9 months ago
    Is there a way that the vlookup comment copies the formatting of the original comment? Some of my comments are very long, but the comment returned from vlookup is always the standard small size, so I can't read all the text
    • To post as a guest, your comment is unpublished.
      skyyang · 9 months ago
      Hello, Carl,
      May be there isn't a direct way for solving your problem, but, you can drag the comment box larger manually. Or you can apply our Kutools for Excel's Autofit Comment feature, it can help you to adjust the comment box to fit the content.Thank you!
  • To post as a guest, your comment is unpublished.
    Josh · 11 months ago
    How would I do the same as an Hlookup instead of vlookup?

    I changed the code as follows:
    Function hlookupComment(LookVal As Variant, FTable As Range, Frow As Long, FType As Long) As Variant
    'Updateby Extendoffice
    Application.Volatile
    Dim xRet As Variant 'could be an error
    Dim xCell As Range
    xRet = Application.Match(LookVal, FTable.Rows(1), FType)
    If IsError(xRet) Then
    hlookupComment = "Not Found"
    Else
    Set xCell = FTable.Rows(Frow).Cells(1)(xRet)
    hlookupComment = xCell.Value
    With Application.Caller
    If Not .Comment Is Nothing Then
    .Comment.Delete
    End If
    If Not xCell.Comment Is Nothing Then
    .AddComment xCell.Comment.Text
    End If
    End With
    End If
    End Function