|
- Sub test()
- Dim r&, i&, m&
- Dim arr, brr()
- Dim reg As New RegExp
- With reg
- .Global = True
- .Pattern = "^\d+$"
- End With
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:a" & r)
- End With
- ReDim brr(1 To 10000, 1 To 8)
- m = 1
- n = 2
- brr(1, 1) = 1
- For i = 1 To UBound(arr)
- If Len(arr(i, 1)) = 0 Then
- m = m + 1
- brr(m, 1) = m
- n = 2
- Else
- brr(m, n) = arr(i, 1)
- n = n + 1
- End If
- Next
- For i = 1 To m
- s = 0
- For j = UBound(brr, 2) To 1 Step -1
- If Len(brr(i, j)) <> 0 Then
- If j <> UBound(brr, 2) Then
- brr(i, 8) = brr(i, j)
- brr(i, j) = Empty
- If Not reg.test(brr(i, 6)) Then
- brr(i, 7) = brr(i, 6)
- brr(i, 6) = Empty
- End If
- End If
- Exit For
- End If
- Next
- Next
- With Worksheets("sheet2")
- .UsedRange.Offset(2, 0).Clear
- .Range("c:d,f:f").NumberFormatLocal = "@"
- .Range("a3").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|