|
代码如下,,,
Sub test()
Dim wb As Workbook, sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
arr = sht.[c1:e360]
ReDim brr(1 To UBound(arr) - 1, 1 To 3)
ReDim drr(1 To UBound(arr) - 1, 1 To 1)
For i = 2 To UBound(arr)
x = Application.Sum(Application.Index(arr, i)) _
- Application.Sum(Application.Index(arr, i - 1))
Select Case Abs(x)
Case 0
brr(i - 1, 1) = "重"
drr(i - 1, 1) = "重"
Case 1
brr(i - 1, 2) = "邻"
drr(i - 1, 1) = "邻"
Case 2
brr(i - 1, 3) = "孤"
drr(i - 1, 1) = "孤"
End Select
Next
ReDim crr(1 To UBound(drr), 1 To 3)
For i = 1 To UBound(drr) - 1
n = 1
For j = i + 1 To UBound(drr)
If drr(j, 1) = drr(i, 1) Then
n = n + 1
Else
If drr(i, 1) = "重" Then
m = m + 1
i = j - 1: crr(m, 1) = n: Exit For
ElseIf drr(i, 1) = "邻" Then
m1 = m1 + 1
i = j - 1: crr(m1, 2) = n: Exit For
Else
m2 = m2 + 1
i = j - 1: crr(m2, 3) = n: Exit For
End If
End If
Next
Next
x = Application.Max(m, m1, m2)
ar = [r1:t1]
br = [q2:q20]
n = 0
ReDim cr(1 To UBound(br), 1 To 3)
Set d = CreateObject("scripting.dictionary")
For i = 1 To UBound(br)
n = n + 1
For j = 1 To UBound(ar, 2)
s = br(i, 1) & ar(1, j)
d(s) = n
Next
Next
For j = 1 To UBound(ar, 2)
For i = 1 To x
If crr(i, j) <> Empty Then
s = crr(i, j) & ar(1, j)
cr(d(s), j) = cr(d(s), j) + 1
End If
Next
Next
[g2:i360,l2:n360,r2:t360].ClearContents
[g2].Resize(UBound(brr), 3) = brr
[l2].Resize(x, 3) = crr
[r2].Resize(UBound(cr), 3) = cr
Set d = Nothing
Beep
End Sub
|
评分
-
1
查看全部评分
-
|