excel中,点选左边表格,则在右侧表格搜索相同数值并标黄
答案:3 悬赏:40 手机版
解决时间 2021-03-24 19:43
- 提问者网友:雨不眠的下
- 2021-03-24 13:33
excel中,点选左边表格,则在右侧表格搜索相同数值并标黄
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-03-24 14:44
你所说的表格1表格2是在同一表格中的两个区域还是两个表互查?如果是前都,那就只要用Worksheet_SelectionChange事件
如果是前者,代码如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng1 As Range, rng2 As Range, ran As Range
Set rng1 = Range("B2:F10")
Set rng2 = Range("H2:L10")
Cells.Interior.ColorIndex = 0
If Not Application.Intersect(Target, rng1) Is Nothing And Target.Count = 1 Then
Target.Interior.ColorIndex = 6
For Each ran In rng2
If ran = Target Then ran.Interior.ColorIndex = 6
Next
End If
If Not Application.Intersect(Target, rng2) Is Nothing And Target.Count = 1 Then
Target.Interior.ColorIndex = 6
For Each ran In rng1
If ran = Target Then ran.Interior.ColorIndex = 6
Next
End If
End Sub
程序中的两个区域,你可根据需要修改追问经测试,可实现上述功能
如果是前者,代码如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng1 As Range, rng2 As Range, ran As Range
Set rng1 = Range("B2:F10")
Set rng2 = Range("H2:L10")
Cells.Interior.ColorIndex = 0
If Not Application.Intersect(Target, rng1) Is Nothing And Target.Count = 1 Then
Target.Interior.ColorIndex = 6
For Each ran In rng2
If ran = Target Then ran.Interior.ColorIndex = 6
Next
End If
If Not Application.Intersect(Target, rng2) Is Nothing And Target.Count = 1 Then
Target.Interior.ColorIndex = 6
For Each ran In rng1
If ran = Target Then ran.Interior.ColorIndex = 6
Next
End If
End Sub
程序中的两个区域,你可根据需要修改追问经测试,可实现上述功能
全部回答
- 1楼网友:骨子里都是戏
- 2021-03-24 16:18
使用程序可以吗
- 2楼网友:琴狂剑也妄
- 2021-03-24 15:33
好容易抽时间做出来了,结果有人已经做好了。就当联系了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯