|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'满意来朵小花哈
'输出到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 |
|