Přejít k hlavnímu obsahu

Jak vlookup a vrátit odpovídající hodnotu s komentářem buňky?

Když použijete funkci Vlookup k vrácení odpovídající hodnoty, extrahuje pouze hodnotu bez formátování, jako je barva výplně, písmo nebo komentář atd. Někdy však možná budete muset vlookup a vrátit odpovídající hodnotu včetně komentáře získat následující výsledek obrazovky. Jak byste mohli vyřešit tuto práci v aplikaci Excel?

Vlookup a návrat odpovídající hodnoty s komentářem buňky pomocí kódu VBA


Vlookup a návrat odpovídající hodnoty s komentářem buňky pomocí kódu VBA

Níže uvedený kód VBA vám může pomoci vlookup a vrátit odpovídající hodnotu s komentářem, postupujte takto:

1. Podržte ALT + F11 klávesy pro otevření Microsoft Visual Basic pro aplikace okno.

2, klikněte Vložit > Modul, poté zkopírujte a vložte následující kód do souboru Modul Okno.

Kód VBA: Vlookup a návrat odpovídající hodnoty s komentářem buňky:

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. A poté uložte kód a zavřete okno s kódem, zadejte tento vzorec: = vlookupcomment (H2, A2: C10,3, FALSE) do prázdné buňky vyhledejte výsledek a stiskněte vstoupit klíč, shodná hodnota i komentář se vrátí najednou, viz screenshot:

Poznámka: Ve výše uvedeném vzorci, H2 je vyhledávací hodnota, kterou chcete vrátit odpovídající hodnotu, A2: C10 je datová tabulka, kterou chcete použít, číslo 3 je číslo sloupce, které obsahuje odpovídající hodnotu, kterou chcete vrátit.

Nejlepší nástroje pro produktivitu v kanceláři

🤖 Kutools AI asistent: Revoluční analýza dat založená na: Inteligentní provedení   |  Generovat kód  |  Vytvořte vlastní vzorce  |  Analyzujte data a generujte grafy  |  Vyvolejte funkce Kutools...
Populární funkce: Najít, zvýraznit nebo identifikovat duplikáty   |  Odstranit prázdné řádky   |  Kombinujte sloupce nebo buňky bez ztráty dat   |   Kolo bez vzorce ...
Super vyhledávání: Více kritérií VLookup    VLookup s více hodnotami  |   VLookup na více listech   |   Fuzzy vyhledávání ....
Pokročilý rozevírací seznam: Rychle vytvořte rozevírací seznam   |  Závislý rozbalovací seznam   |  Vícenásobný výběr rozevíracího seznamu ....
Správce sloupců: Přidejte konkrétní počet sloupců  |  Přesunout sloupce  |  Přepnout stav viditelnosti skrytých sloupců  |  Porovnejte rozsahy a sloupce ...
Doporučené funkce: Zaměření mřížky   |  Návrhové zobrazení   |   Velký Formula Bar    Správce sešitů a listů   |  Knihovna zdrojů (Automatický text)   |  Výběr data   |  Zkombinujte pracovní listy   |  Šifrovat/dešifrovat buňky    Odesílat e-maily podle seznamu   |  Super filtr   |   Speciální filtr (filtr tučné/kurzíva/přeškrtnuté...) ...
Top 15 sad nástrojů12 Text Tools (doplnit text, Odebrat znaky, ...)   |   50+ Graf Typ nemovitosti (Ganttův diagram, ...)   |   40+ Praktické Vzorce (Vypočítejte věk na základě narozenin, ...)   |   19 Vložení Tools (Vložte QR kód, Vložit obrázek z cesty, ...)   |   12 Konverze Tools (Čísla na slova, Přepočet měny, ...)   |   7 Sloučit a rozdělit Tools (Pokročilé kombinování řádků, Rozdělit buňky, ...)   |   ... a více

Rozšiřte své dovednosti Excel pomocí Kutools pro Excel a zažijte efektivitu jako nikdy předtím. Kutools for Excel nabízí více než 300 pokročilých funkcí pro zvýšení produktivity a úsporu času.  Kliknutím sem získáte funkci, kterou nejvíce potřebujete...

Popis


Office Tab přináší do Office rozhraní s kartami a usnadňuje vám práci

  • Povolte úpravy a čtení na kartách ve Wordu, Excelu, PowerPointu, Publisher, Access, Visio a Project.
  • Otevřete a vytvořte více dokumentů na nových kartách ve stejném okně, nikoli v nových oknech.
  • Zvyšuje vaši produktivitu o 50%a snižuje stovky kliknutí myší každý den!
Comments (20)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
txs a lot. highly appreciated!
This comment was minimized by the moderator on the site
Hello this is a very good function, but it works for Notes, not Comments (this is how it is translated in my native language at least). Is there some way to change it from Notes to Comments? Also, is there a way to keep the cell format? (color of the original cell, etc).
This comment was minimized by the moderator on the site
i've had the same issue. i can only say that having tried via vba to copy comments and notes... only notes are being copied, not the comments (although the have the same meaning, but a different functionality)... Notes seem to be of a static nature, unlike comments where you can keep "posting" to adding new text...Probably that's the reason....
This comment was minimized by the moderator on the site
Hi, fana,
To extract the matched records with the comment in Office 365, please apply the below code:
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 .CommentThreaded Is Nothing Then
                .ClearComments
            End If
            If Not xCell.CommentThreaded Is Nothing Then
                .AddCommentThreaded xCell.CommentThreaded.Text
            End If
        End With
    End If
End Function


After pasting the code, apply this formula: =vlookupcomment(H2,A2:C10,3,FALSE) as well.

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Not working for me. I get #NAME? error when i use this formula. Please help.
This comment was minimized by the moderator on the site
Hello, Sajjad,Did you put the VBA code of this article into your workbook? Please check it.Or which Excel version do you use?Thank you!
This comment was minimized by the moderator on the site
This is a wonderful. But when using this code I find the file crashes a lot on Excel 365. when removing auto save I found it’s a little better. But with multiple users in the file, the file will crash all the time. Does this code use a lot of memory or is it a compatibility issue? Thoughts? Thanks
This comment was minimized by the moderator on the site
Hi! I'm so glad I found this, the thing is, this actually works on notes, and not comments. is there a way to have work on comments and not notes? in notes i cannot tag my coworkers and i cannot reply either. thanks a lot!
This comment was minimized by the moderator on the site
i can do that at the first time. but after i try to use changing formula of multiple cells. It doesn't work now. after even i type vlookupcomment, the cell becomes blank.
This comment was minimized by the moderator on the site
My comment is too large for the default box size. Is there any way to increase the comment box size or possibly decrease the font size?
This comment was minimized by the moderator on the site
If anyone else needs this.


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 = "-"

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

.Comment.Shape.ScaleWidth 2, msoFalse, msoScaleFromTopLeft

.Comment.Shape.ScaleHeight 2.5, msoFalse, msoScaleFromTopLeft

End If

End With

End If

End Function
This comment was minimized by the moderator on the site
I want only Comment as Cell Value using Vlookup...
This comment was minimized by the moderator on the site
Thanks, It's helpful & I have something to askIt returns with cell comment but the Image (Inserted using fill effects ) does not show
Please , help me out of this Issue
This comment was minimized by the moderator on the site
Shamim,
Sorry for that there is no direct code for solving your problem, if anyone has the solution, please comment here.
This comment was minimized by the moderator on the site
Frank
Hello,

In case of spreadsheet protected, when I open my workbook the cell return the error #VALUE!

How we can solve this problem?
This comment was minimized by the moderator on the site
Hello, Frank,
After inserting the code, you should save your workbook as Excel Macro-Enabled Workbook format, so that the code will not lose.
Please try! Thank you!
This comment was minimized by the moderator on the site
Can we use cell in column B (order column) as comment for cell in column C (name). exc, comment for Helen is 80.
thank you for your help.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations