|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Dim arr, brr, d As Object, i&, j&, k&, x$
- Set d = CreateObject("scripting.dictionary")
- arr = Range("a2:r" & Range("a65536").End(xlUp).Row)
- Range("a2:q" & UBound(arr)).ClearContents
- arr(1, 18) = 1
- For i = 2 To UBound(arr)
- If arr(i, 1) & "," & arr(i, 5) & "," & arr(i, 9) & "," & arr(i, 10) & "," & arr(i, 14) = arr(i - 1, 1) & "," & arr(i - 1, 5) & "," & arr(i - 1, 9) & "," & arr(i - 1, 10) & "," & arr(i - 1, 14) Then
- arr(i, 18) = arr(i - 1, 18)
- Else
- arr(i, 18) = arr(i - 1, 18) + 1
- End If
- Next
- For i = 1 To UBound(arr)
- x = arr(i, 1) & "," & arr(i, 5) & "," & arr(i, 9) & "," & arr(i, 10) & "," & arr(i, 14) & "," & arr(i, 18)
- d(x) = d(x) & "," & arr(i, 7)
- Next
- ReDim brr(1 To d.Count, 1 To UBound(arr, 2) - 1)
- a = d.keys: b = d.items
- For j = 0 To d.Count - 1
- m = Split(b(j), ",")
- For i = 1 To UBound(arr)
- x = arr(i, 1) & "," & arr(i, 5) & "," & arr(i, 9) & "," & arr(i, 10) & "," & arr(i, 14) & "," & arr(i, 18)
- If a(j) = x Then
- For k = 1 To UBound(arr, 2) - 1
- brr(j + 1, k) = arr(i, k)
- Next
- brr(j + 1, 7) = IIf(m(0) = "", m(1), m(0))
- brr(j + 1, 6) = Right(brr(j + 1, 7), 2)
- brr(j + 1, 8) = m(UBound(m))
- End If
- Next
- Next
- Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
复制代码 |
|