|
- Sub test()
- Dim r%, i%
- Dim arr, brr, zrr()
- With Worksheets("201808")
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- c = .Cells(3, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- m = 0
- For i = 1 To UBound(arr)
- If arr(i, 1) = "编号" Then
- m = m + 1
- ReDim Preserve zrr(1 To 2, 1 To m)
- zrr(1, m) = i
- zrr(2, m) = i
- Else
- If m <> 0 Then
- zrr(2, m) = i
- End If
- End If
- Next
- ReDim brr(1 To UBound(arr, 2) / 4 * UBound(arr), 1 To 3)
- m = 0
- For k = 1 To UBound(zrr, 2)
- For i = zrr(1, k) + 1 To zrr(2, k) - 1
- For j = 1 To UBound(arr, 2) Step 4
- If Len(arr(i, j)) <> 0 Then
- m = m + 1
- brr(m, 1) = arr(i, j)
- brr(m, 2) = arr(i, j + 1)
- brr(m, 3) = arr(i, j + 2)
- End If
- Next
- Next
- Next
-
- End With
- With Worksheets("sheet2")
- .Range("a2").Resize(m, UBound(brr, 2)) = brr
- End With
-
- End Sub
复制代码 |
|