|
代码如下。。。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$D$1" Then
arr = [b11:b110]
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr) - 1
If arr(i, 1) > 0 Then
n = 1: m = 1
For j = i + 1 To UBound(arr) - 1
If arr(j, 1) > 0 And j + 1 <> UBound(arr) Then
n = n + 1: m = m + 1
ElseIf arr(j, 1) = 0 And arr(j + 1, 1) > 0 And j + 1 <> UBound(arr) Then
' If arr(j, 1) > 0 Then n = n + 1
m = m + 1
ElseIf j + 1 = UBound(arr) Then
If arr(j, 1) > 0 And m > 1 Then If arr(j + 1, 1) > 0 Then m = m + 2: n = n + 2 Else m = m + 1: n = n + 1
If m > 3 Then
For k = i To i + m - 1
brr(k, 1) = n
Next
End If
i = j
Exit For
Else 'If j + 1 <> UBound(arr) Then
If m > 3 Then
For k = i To j - 1
brr(k, 1) = n
Next
End If
i = j
Exit For
End If
Next
End If
Next
For i = 1 To UBound(brr)
If brr(i, 1) = Empty Then brr(i, 1) = 0
Next
[d11].Resize(UBound(brr)) = brr
Beep
End If
Application.EnableEvents = True
End Sub
|
评分
-
2
查看全部评分
-
|