|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
'满意来朵小花哈
'输出到G列,自己修改,因为你得示例中有错误,给你作比较
Option Explicit
Sub test()
Dim i, j, arr, brr, n
arr = Range("a2:e" & [e65536].End(xlUp).Row)
ReDim brr(1 To UBound(arr, 1), 1 To UBound(arr, 2))
For i = 1 To UBound(arr, 1)
If Len(arr(i, 2)) > 0 Then n = n + 1
brr(i, 2) = n
Next
n = 0
For i = 2 To UBound(arr, 1)
If brr(i - 1, 2) <> brr(i, 2) Then n = 0
If Len(arr(i, 3)) > 0 Then n = n + 1
brr(i, 3) = n
Next
n = 0
For i = 3 To UBound(arr, 1)
If brr(i - 1, 3) <> brr(i, 3) Then n = 0
If Len(arr(i, 4)) > 0 Then n = n + 1
brr(i, 4) = n
Next
n = 0
For i = 4 To UBound(arr, 1)
If brr(i - 1, 4) <> brr(i, 4) Then n = 0
If Len(arr(i, 5)) > 0 Then n = n + 1
brr(i, 5) = n
Next
For i = 1 To UBound(brr, 1)
For j = 2 To UBound(brr, 2)
brr(i, 1) = brr(i, 1) & brr(i, j)
Next
brr(i, 1) = Replace(brr(i, 1), "0", vbNullString)
Next
[g2].Resize(UBound(arr, 1), 1) = brr
End Sub |
|