|
Sub 按钮1_Click()
n = 4
Set Rng = Nothing
Set d = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
For i = 1 To UBound(arr, 2)
For j = 1 To UBound(arr)
d(arr(j, i)) = d(arr(j, i)) & "," & Cells(j, i).Address(0, 0)
Next j
Next i
For Each k In d.keys
brr = Split(d(k), ",")
If UBound(brr) >= n Then
Set rngx = Nothing
w = get_ok(brr, n, rngx)
If get_ok(brr, n, rngx) Then
If Rng Is Nothing Then
Set Rng = rngx
Else
Set Rng = Union(Rng, rngx)
End If
End If
End If
Next k
If Not Rng Is Nothing Then
Rng.Font.ColorIndex = 3
End If
End Sub
Function get_ok(brr, n, rngx)
get_ok = False
x = 1
y = Range(brr(1)).Column
Set rngx = Range(brr(1))
For j = 2 To UBound(brr)
If Range(brr(j)).Column - y <> 1 Then
If x >= 4 Then
get_ok = True
Exit Function
Else
x = 1
y = Range(brr(j)).Column
Set rngx = rngx
End If
Else
x = x + 1
y = Range(brr(j)).Column
Set rngx = Union(rngx, Range(brr(j)))
End If
Next j
If x >= 4 Then get_ok = True
End Function |
|