当前位置: 代码迷 >> Office >> excel 链接到指定数据,该怎么处理
  详细解决方案

excel 链接到指定数据,该怎么处理

热度:9599   发布时间:2013-02-26 00:00:00.0
excel 链接到指定数据
表一
A1 A2 
1 01 
2 02 
表二
A1 A2 A3
1 01 100
2 01 15
3 02 25
4 02 63

要求:在表一中A2列建立超链接,点击后直接定位到表二中与表一关联的数据行


------解决方案--------------------------------------------------------
sheet2里加个selectionchange事件

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub
If Len(Target.Value) = 0 Then Exit Sub
Dim findResult
Dim lRow&
Set findResult = Sheet1.Range("a:a").Find(Cells(Target.Row, 1).Value, , xlValues, xlWhole)
If findResult Is Nothing Then Exit Sub
lRow = findResult.Row
Sheet1.Activate
Sheet1.Rows(lRow).Select
End Sub
------解决方案--------------------------------------------------------
探讨
sheet2里加个selectionchange事件

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column <> 2 Then Exit Sub
    If Target.Row = 1 Then Exit Sub
    If Len(Target.Value) = 0 Then Exit Sub
    Dim findResult
    Dim lRow&
    Set findResult = Sheet1.Range("a:a").Find(Cells(Target.Row, 1).Value, , xlValues, xlWhole)
    If findResult Is Nothing Then Exit Sub
    lRow = findResult.Row
    Sheet1.Activate
    Sheet1.Rows(lRow).Select
End Sub
  相关解决方案