Sub TEST_A1()
Dim Arr, Brr, i&, j%, k%, Cn%, V%, V1%, V2%, N&, R&
Sheets("Sheet2").[a:j].ClearContents
Arr = Range(Sheets("Sheet1").[j1], Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp)(2))
ReDim Brr(1 To 30000, 1 To 10)
For i = 2 To UBound(Arr) - 1
V = IIf(Arr(i, 10) = "HT", 1000, 3000) '除數
V1 = Val(Arr(i, 7)) '數量
Cn = Int(V1 / V) + 1 '分拆行數
V2 = V1 Mod V '餘數
If V2 < 101 And Cn > 1 Then Cn = Cn - 1: V2 = V + V2
For j = 1 To Cn
N = N + 1
For k = 1 To 10: Brr(N, k) = Arr(i, k): Next
Brr(N, 7) = IIf(j = Cn, V2, V)
Next j
If Arr(i, 8) <> Arr(i + 1, 8) And N Mod 2 = 1 Then N = N + 1
Next i
Sheets("Sheet2").[a1:j1] = Sheets("Sheet1").[a1:j1].Value
Sheets("Sheet2").[a2].Resize(N, 10) = Brr
End Sub作者: stephenlee 時間: 2021-10-26 08:02
Sub TEST_A1()
Dim Arr, Brr, i&, j%, k%, Cn%, V%, V1%, V2%, N&, R&
Sheets("Sheet2").[a:j].ClearCont ...
准提部林 發表於 2021-10-24 16:54