试试:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = 0
If Target.Column <= 27 And Target.Row <= 3000 Then
Range("A1:AA3000").Interior.ColorIndex = xlNone
k = Target
If Len(Target) < 1 Then k = 0
Set cl = Range("A1:AA3000").Find(k, , , xlWhole)
If Not cl Is Nothing Then
firstAddress = cl.Address
Do
cl.Interior.ColorIndex = 4
Set cl = Range("A1:AA3000").FindNext(cl)
Loop While Not cl Is Nothing And cl.Address <> firstAddress
End If
试试:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = 0
If Target.Column <= 27 And Target.Row <= 3000 Then
Range("A1:AA3000").Interior.ColorIndex = xlNone
k = Target
If Len(Target) < 1 Then k = 0
Set cl = Range("A1:AA3000").Find(k, , , xlWhole)
If Not cl Is Nothing Then
firstAddress = cl.Address
Do
cl.Interior.ColorIndex = 4
Set cl = Range("A1:AA3000").FindNext(cl)
Loop While Not cl Is Nothing And cl.Address <> firstAddress
End If