|
换个思路- Private Sub CommandButton1_Click()
- Dim arr, i&, j&
- Dim iStart&, iEnd&
- Dim xFlag As Boolean
- Dim iRng As Range
- With Sheet1
- arr = .Range("a1").CurrentRegion.Value
- For j = 3 To UBound(arr, 2)
- For i = 2 To UBound(arr)
- If arr(i, j) = 8 Then
- If xFlag = False Then iStart = i: xFlag = True
- ElseIf xFlag = True Then
- iEnd = i - 1
- If iEnd - iStart >= 7 Then
- If iRng Is Nothing Then
- Set iRng = .Range(.Cells(iStart, j), .Cells(iEnd, j))
- Else
- Set iRng = Union(iRng, .Range(.Cells(iStart, j), .Cells(iEnd, j)))
- End If
- End If
- xFlag = False
- End If
- Next
- Next
- If Not iRng Is Nothing Then iRng.Interior.ColorIndex = 3
- End With
- End Sub
复制代码 |
|