【问题标题】:Create hyperlink which links to cell with matching text in next sheet创建链接到下一张表中匹配文本的单元格的超链接
【发布时间】:2019-10-07 13:58:22
【问题描述】:

我想用超链接替换 ​​sheet1 的 B 列中存在的所有文本,这些超链接将遍历具有上述文本的工作表和单元格(第二次出现)。

假设我们有 sheet1:

Column A : Column B
T1       : Brand Values
T2       : Brand Text

就像我们可以通过 Find all 选项来实现一样。

因此,对于上述选项,请创建指向 Sheet 2 单元格引用 A3 的超链接。

我得到了创建链接的 VBA 代码:

ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= "'" & sh.Name & "'" & "!A1", TextToDisplay:=sh.Name

如何在另一个工作表中找到匹配文本的单元格引用?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    为每个工作表找到匹配项。

    然后将匹配的地址写入超链接。

    Sub test()
        Dim mySht As Worksheet, sht As Worksheet
        Dim cell As Range, myRng As Range
    
        Set mySht = ActiveSheet
        For Each cell In mySht.Range("B2:B3")
            For Each sht In Worksheets
                If sht.Name <> mySht.Name Then    ' find each worksheet except myself
                    Set myRng = Nothing
                    On Error Resume Next
                    Set myRng = sht.Cells.Find(what:=cell.Value, LookIn:=xlValues, lookat:=xlWhole)    ' find match
                    If Not myRng Is Nothing Then
                        mySht.Hyperlinks.Add _
                            anchor:=cell, _
                            Address:="", _
                            SubAddress:=myRng.Address(True, True, xlA1, True), _
                            TextToDisplay:=cell.Value
                        Exit For
                    End If
                    On Error Goto 0
                End If
            Next sht
        Next cell
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2021-05-12
      • 2018-06-30
      • 2017-07-23
      • 1970-01-01
      • 2016-01-23
      • 2011-02-15
      相关资源
      最近更新 更多