excel如何实现在选定的区域内,当点击其中一个单元格,与选中单元格相同的数值都被显示为红色?

excel如何实现在选定的区域内,当点击其中一个单元格,与选中单元格相同的数值都被显示为红色?请高手帮忙解答!非常感谢!

比如我想实现:当我点张三的单元格,在这个范围内,两个张三都被显示为红色,用vba如何实现!

要用VBA了。使用 Worksheet_SelectionChange事件,
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'使用find查找区域内等于Target的值,得到地址。
'使用FormatConditions. 比如:
'Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual,Formula1:="="&target.value
‘Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

’With Selection.FormatConditions(1).Font
‘ .Color = -16383844
’ .TintAndShade = 0
‘End With

End Sub
我都注释掉了,现在没法测试,自己试一下吧。。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-14
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Dim rng As Range
If Target.Count = 1 And Target <> "" Then
   Cells.Interior.ColorIndex = -4142
   For Each rng In UsedRange
       If rng = Target.Value Then
          rng.Interior.ColorIndex = 3
       End If
   Next
End If
End Sub

本回答被提问者采纳
相似回答