|
用这段代码吧,把“总览”和F3:F63的范围根据自己实际的表改一下就行了。
前两天刚整的
当“总览”表中,F3:F63与其余表有相同时,建立双向超级链接。
Sub CreateHyperlinks()
Dim overviewSheet As Worksheet
Set overviewSheet = ThisWorkbook.Sheets("总览")
Dim cell As Range
For Each cell In overviewSheet.Range("F3:F63")
Dim cellValue As String
cellValue = cell.value
If Len(cellValue) > 0 Then
Dim hyperlinkRange As Range
Set hyperlinkRange = Nothing
Dim sheet As Worksheet
For Each sheet In ThisWorkbook.Sheets
If sheet.Name <> overviewSheet.Name Then
Dim searchRange As Range
Set searchRange = sheet.UsedRange
Dim foundCell As Range
Set foundCell = searchRange.Find(cellValue, LookIn:=xlValues, LookAt:=xlWhole)
If Not foundCell Is Nothing Then
If hyperlinkRange Is Nothing Then
Set hyperlinkRange = cell
End If
overviewSheet.Hyperlinks.Add Anchor:=cell, Address:="", SubAddress:= _
"'" & sheet.Name & "'!" & foundCell.Address, TextToDisplay:=cellValue
sheet.Hyperlinks.Add Anchor:=foundCell, Address:="", SubAddress:= _
"'" & overviewSheet.Name & "'!" & cell.Address, TextToDisplay:=cellValue
End If
End If
Next sheet
If Not hyperlinkRange Is Nothing Then
hyperlinkRange.Select
End If
End If
Next cell
End Sub |
|