如何在当前单元格上使用HYPERLINK和VLOOKUP?

问题描述

为此跟踪标签提供列表:

enter image description here

如何添加链接,因此,如果单击 OBS1001 ,它将指向名为存储库

的此选项卡。

enter image description here

我已经使用过类似=HYPERLINK(VLOOKUP("OBS1001";'Repository'!$B$3:$Y$1052;1;0);"OBS1001")的东西,但是我得到了#N/A

解决方法

VLookup()仅从工作表Repository返回一个值,该值不是超链接的任何有效引用。尝试下面的公式-

=HYPERLINK("#Repository!A" & MATCH(A2,Repository!A:A,0),A2)

enter image description here

编辑:VBA方法。

如果要向代码单元添加超链接,请使用以下子项。

Sub AddHyperlinks()
Dim lRow As Long,hRow As Long
Dim Rng As Range

lRow = Range("A1").End(xlDown).Row

    For Each Rng In Range("A2:A" & lRow)
        hRow = Application.WorksheetFunction.Match(Rng,Range("Repository!A:A"),0)
        ActiveSheet.Hyperlinks.Add Anchor:=Range(Rng.Address),_
                    Address:="#Repository!A" & hRow,_
                    ScreenTip:=Rng.Value2,_
                    TextToDisplay:=Rng.Value2
    Next
End Sub