|
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range, x As Range, t As Range
Dim r1 As Integer, c1 As Integer, r2 As Integer, c2 As Integer
Dim t1 As Boolean, t2 As Boolean, t3 As Boolean
Set rng = [a1:d4]
Set t = Target
If Application.Intersect(t, rng) Is Nothing Or t.Count > 1 Then Exit Sub
r1 = t.Row: c1 = t.Column
For Each x In rng
r2 = x.Row: c2 = x.Column
t1 = (r2 = r1) And (Abs(c2 - c1) = 1) '左右
t2 = (c2 = c1) And (Abs(r2 - r1) = 1) '上下
t3 = (Abs(r2 - r1) = 1) And (Abs(c2 - c1) = 1) '四角
If t1 Or t2 Or t3 Then
x.Interior.ColorIndex = IIf(x.Interior.ColorIndex = xlNone, 4, xlNone)
End If
Next
End Sub
gd.rar
(9.75 KB, 下载次数: 6)
|
|