[Quote=引用 6 楼 laoyebin 的回复:]
[/Quote]
参考你的,我修改了如下:
A2列关联
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Len(Target.Value) = 0 Then Exit Sub
Dim findResult
Dim lRow&
Set findResult = Sheet1.Range("b:b").Find(Target.Text, , xlValues, xlWhole)
If findResult Is Nothing Then Exit Sub
lRow = findResult.Row
Sheet1.Activate
Sheet1.Rows(lRow).Select
End Sub
A1列关联
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column <> 2 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).Text, , xlValues, xlWhole)
If findResult Is Nothing Then Exit Sub
lRow = findResult.Row
Sheet1.Activate
Sheet1.Rows(lRow).Select
End Sub
第一行是表头还要加上If Target.Row = 1 Then Exit Sub 参考laoyebin
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
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
[/Quote]
看了很久,终于有些明白了,不过你好像理解错了楼主的意思,这个selectionchange事件应该加在表一上。
楼主也没说明白如何关联,是转到相同行呢(A1列相同)?还是转到A2列的值相同的行中?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Len(Target.Value) = 0 Then Exit Sub
Dim findResult
Dim lRow&
Set findResult = Sheet2.Range("a:a").Find(Cells(Target.Row, 1).Text, , xlValues, xlWhole)
If findResult Is Nothing Then Exit Sub
lRow = findResult.Row
Sheet2.Activate
Sheet2.Rows(lRow).Select
End Sub
A2关联方法类似,呵呵。再次谢谢laoyebin!
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