Sub 按钮1_Click()
arr = [a1].CurrentRegion
brr = [a1].Resize(UBound(arr) * 2, UBound(arr, 2))
r = 1
For j = 2 To UBound(arr)
If arr(j, 5) * 100 Mod arr(j, 4) = 0 Then
r = r + 1
For i = 1 To UBound(arr, 2) - 1
brr(r, i) = arr(j, i)
Next i
brr(r, i) = arr(j, 5) / arr(j, 4)
Else
x = Int(arr(j, 5) * 100 / arr(j, 4))
For i = 1 To arr(j, 4)
If i * x + (arr(j, 4) - i) * (x + 1) = arr(j, 5) * 100 Then
r = r + 1
For k = 1 To UBound(arr, 2) - 1
brr(r, k) = arr(j, k)
brr(r + 1, k) = arr(j, k)
Next k
brr(r, 4) = i
brr(r + 1, 4) = arr(j, 4) - i
brr(r, 6) = x / 100
brr(r + 1, 6) = (x + 1) / 100
brr(r, 5) = brr(r, 4) * brr(r, 6)
brr(r + 1, 5) = brr(r + 1, 4) * brr(r + 1, 6)
r = r + 1
Exit For
End If
Next i
End If
Next j
[o1].Resize(r, UBound(brr, 2)) = brr
End Sub
|