|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下。。。
Sub test()
Dim wb As Workbook, sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
For i = 3 To 5
r = sht.Cells(Rows.Count, i).End(3).Row
x = Application.Max(r, x)
Next
arr = sht.Range("c1:e" & x)
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) And j <> UBound(drr) Then
n = n + 1
ElseIf drr(j, 1) <> drr(i, 1) And j <> UBound(drr) Then 'Or j = UBound(drr)
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
ElseIf drr(j, 1) = drr(i, 1) And j = UBound(drr) Then
If drr(i, 1) = "重" Then
m = m + 1
i = j - 1: crr(m, 1) = n + 1: Exit For
ElseIf drr(i, 1) = "邻" Then
m1 = m1 + 1
i = j - 1: crr(m1, 2) = n + 1: Exit For
Else
m2 = m2 + 1
i = j - 1: crr(m2, 3) = n + 1: Exit For
End If
ElseIf drr(j, 1) <> drr(i, 1) And j = UBound(drr) Then
If drr(i, 1) = "重" Then
m = m + 1
crr(m, 1) = 1
ElseIf drr(i, 1) = "邻" Then
m1 = m1 + 1
crr(m1, 2) = 1
Else
m2 = m2 + 1
crr(m2, 3) = 1
End If
If drr(j, 1) = "重" Then
m = m + 1
i = j - 1: crr(m, 1) = 1: Exit For
ElseIf drr(j, 1) = "邻" Then
m1 = m1 + 1
i = j - 1: crr(m1, 2) = 1: Exit For
Else
m2 = m2 + 1
i = j - 1: crr(m2, 3) = 1: 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
|
评分
-
3
查看全部评分
-
|