gpt4 book ai didi

excel - 模拟指向另一个表中相应单元格的超链接

转载 作者:行者123 更新时间:2023-12-04 22:18:51 25 4
gpt4 key购买 nike

当我双击一个表格中的单元格时,如何模拟指向另一个表格中相应单元格的超链接?我收到 sCellAddress 的类型不匹配错误.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Set tb = ActiveSheet.ListObjects("Table1")
If Not Intersect(Target, tb.ListColumns("Site").DataBodyRange) Is Nothing Then
Cancel = True
Dim sCellAddress As String
sCellAddress = [CELL("address", INDEX(Sites[Base], MATCH([@Site], Sites[Site], 0)))]
Application.Goto ActiveSheet.Range(sCellAddress)
End If
End Sub
另外,如何为 RangeExclude 指定多个范围?
Private Sub Workbook_SheetBeforeDoubleClick(ByVal sH As Object, ByVal Target As Range, Cancel As Boolean)
Dim ShExclude As Worksheet, RangeExclude As Range
Set ShExclude = ThisWorkbook.Worksheets("Sheet1")
Set RangeExclude = ShExclude.ListObjects("Table1").ListColumns("Sites").DataBodyRange
End Sub

最佳答案

这就是我将如何做到的

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim loFrom As ListObject
Dim loTo As ListObject
Dim rFound As Range

Set loFrom = Me.ListObjects("tblOne")
Set loTo = Me.ListObjects("tblTwo")

If Not Intersect(loFrom.ListColumns("Site").DataBodyRange, Target) Is Nothing Then
Set rFound = loTo.ListColumns("Site").DataBodyRange.Find(Target.Value, , xlValues, xlWhole)
If Not rFound Is Nothing Then
rFound.Select
End If
End If

End Sub
在将具有该值的 ListColumn 中,执行 Find 以查看它是否在其中。如果是,请选择它。

关于excel - 模拟指向另一个表中相应单元格的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66176042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com