- Sub test()
- Dim r%, i%
- Dim arr, brr, crr()
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:o" & r)
- End With
- ReDim brr(1 To UBound(arr) * 10, 1 To UBound(arr, 2))
- m = 0
- For i = 1 To UBound(arr)
- ReDim crr(1 To UBound(arr, 2))
- For Each y In Array(7, 8, 9, 10, 11, 13, 14)
- crr(y) = Split(arr(i, y), "")
- Next
- xq = arr(i, 5)
- For k = 0 To UBound(crr(7))
- m = m + 1
- For Each y In Array(1, 2, 3, 4, 5, 6, 15)
- brr(m, y) = arr(i, y)
- Next
- For Each y In Array(7, 8, 9, 10, 11, 13, 14)
- If y = 11 Then
- brr(m, y) = Val(crr(y)(k))
- Else
- brr(m, y) = crr(y)(k)
- End If
- Next
-
- If k = 0 Then
- brr(m, 12) = brr(m, 11)
- Else
- brr(m, 12) = brr(m - 1, 12) + brr(m, 11)
- End If
- ' If m = 10 Then Stop
- If xq = 0 Then
- brr(m, 5) = 0
- brr(m, 6) = 0
- Else
- If xq > brr(m, 11) Then
- If k <> UBound(crr(7)) Then
- xq = xq - brr(m, 11)
- brr(m, 5) = brr(m, 11)
- brr(m, 6) = 0
- Else
- brr(m, 5) = xq
- brr(m, 6) = brr(m, 11) - xq
- End If
- ElseIf xq < brr(m, 11) Then
- brr(m, 5) = xq
- brr(m, 6) = brr(m, 11) - xq
- xq = 0
- End If
- End If
- Next
- Next
- With Worksheets("模板")
- .UsedRange.Offset(1, 0).ClearContents
- .Range("a2").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |