参考:club.excelhome.net/thread-1233237-1-1.html
改后代码实现:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = UsedRange
If Target.Count > 1 Then
Set Target = Target.Cells(1)
End If
If Application.Intersect(Target, rng) Is Nothing Or Target.Value = "" Then Exit Sub
Dim c As Range
For Each ws In Worksheets
Set rng = ws.UsedRange
rng.Interior.ColorIndex = xlNone
For Each c In rng
If c.Value = Target.Value Then
c.Interior.ColorIndex = 28
End If
Next
Next
End Sub
效果:
参考:
http://blog.csdn.net/dkman803/article/details/1904194Excel VBA Interior.ColorIndex 色彩列表 http://club.excelhome.net/thread-1182429-1-1.html http://blog.sina.com.cn/s/blog_5380518001011en5.html |Excel VBA中选取单元格的方法(转) http://www.exceltip.net/thread-52203-1-1.html |[操作与技巧] 如何用VBA求出两个区域的差集,交集,并集 选择特定颜色单元格:http://club.excelhome.net/thread-1182429-1-1.html excel vba中如何表示某单元格的旁边一个单元格?https://zhidao.baidu.com/question/90476405.html 请教如何将表格中A列包含指定内容的单元格右移一格 http://www.excelpx.com/thread-369641-1-1.html excel target对象 https://www.kafan.cn/edu/46645252.html