动态超链接可vlookup可vlookup一个单元格值,并找到从数组到输入到URL的相应​​ID

发布于 2025-01-28 19:47:38 字数 709 浏览 2 评论 0原文

在这种情况下,我想vlookup vookup value,并将其与列r:r中的ID匹配。 Q列:Q是可以找到单元格的地方。

单元格值可用并提取信息。我不能把它带到vlookup。

Public Sub Login_To_Hyperlink()
    Dim VBAIDPull As Range
    Dim Cell As Range
    Dim ID As String
    
    Set VBAIDPull = Workbooks("testupdated.xlsm").Sheets("Overview").Range("Q2:Q250,R2:R250")

    ID = Application.WorksheetFunction.VLookup(Cell.Value, VBAIDPull, 2, False)

    For Each Cell In Range("A2:A250")
        If Cell <> "" Then
            ActiveSheet.Hyperlinks.Add Anchor:=Cell, _
            Address:=Cell.Value, _
            ScreenTip:=ID, _
            TextToDisplay:=Cell.Value
        End If
    Next
End Sub

I want to VLOOKUP the cell.value in this case and match it to the ID in column R:R. Column Q:Q is where the cell.value can be found.

The cell.value works and pulls the info. I can't get it to vlookup.

Public Sub Login_To_Hyperlink()
    Dim VBAIDPull As Range
    Dim Cell As Range
    Dim ID As String
    
    Set VBAIDPull = Workbooks("testupdated.xlsm").Sheets("Overview").Range("Q2:Q250,R2:R250")

    ID = Application.WorksheetFunction.VLookup(Cell.Value, VBAIDPull, 2, False)

    For Each Cell In Range("A2:A250")
        If Cell <> "" Then
            ActiveSheet.Hyperlinks.Add Anchor:=Cell, _
            Address:=Cell.Value, _
            ScreenTip:=ID, _
            TextToDisplay:=Cell.Value
        End If
    Next
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2025-02-04 19:47:38

这可能是您想要的:

Public Sub Login_To_Hyperlink()
    Dim VBAIDPull As Range, ws As Worksheet
    Dim Cell As Range, ID As Variant 'not string
    
    'you can use ThisWorkbook.Sheets() if your table's in the same workbook as your code
    Set VBAIDPull = Workbooks("testupdated.xlsm").Sheets("Overview").Range("Q2:R250")
    Set ws = ActiveSheet
    
    For Each Cell In ws.Range("A2:A250").Cells
        If Cell.Value <> "" Then
            ID = Application.VLookup(Cell.Value, VBAIDPull, 2, False)
            If Not IsError(ID) Then 'got a match?
                ws.Hyperlinks.Add Anchor:=Cell, _
                    Address:=Cell.Value, _
                    ScreenTip:=ID, _
                    TextToDisplay:=Cell.Value
            End If 'got a match
        End If     'cell has value
    Next Cell
End Sub

This might be close what you want:

Public Sub Login_To_Hyperlink()
    Dim VBAIDPull As Range, ws As Worksheet
    Dim Cell As Range, ID As Variant 'not string
    
    'you can use ThisWorkbook.Sheets() if your table's in the same workbook as your code
    Set VBAIDPull = Workbooks("testupdated.xlsm").Sheets("Overview").Range("Q2:R250")
    Set ws = ActiveSheet
    
    For Each Cell In ws.Range("A2:A250").Cells
        If Cell.Value <> "" Then
            ID = Application.VLookup(Cell.Value, VBAIDPull, 2, False)
            If Not IsError(ID) Then 'got a match?
                ws.Hyperlinks.Add Anchor:=Cell, _
                    Address:=Cell.Value, _
                    ScreenTip:=ID, _
                    TextToDisplay:=Cell.Value
            End If 'got a match
        End If     'cell has value
    Next Cell
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文