|
Sub 生成()
Dim ar As Variant
Dim br()
With Sheet1
r = .Cells(Rows.Count, 4).End(xlUp).Row
ar = .Range("d1:h" & r)
sl = Application.Sum(.Range("h2:h" & r))
ReDim br(1 To sl, 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" And Trim(ar(i, 3)) <> "" Then
If IsNumeric(ar(i, 2)) And IsNumeric(ar(i, 3)) Then
If ar(i, 2) / ar(i, 3) = Int(ar(i, 2) / ar(i, 3)) Then
gs = ar(i, 2) / ar(i, 3)
Else
gs = Int(ar(i, 2) / ar(i, 3)) + 1
End If
For s = 1 To gs
n = n + 1
br(n, 1) = ar(i, 1)
If s < gs Then
br(n, 2) = ar(i, 2)
Else
br(n, 2) = ar(i, 3)
End If
br(n, 3) = Format(n, "00")
Next s
End If
End If
Next i
If n = "" Then End
.[s1].CurrentRegion.Offset(1) = Empty
.[s2].Resize(n, 3) = br
End With
MsgBox "ok!"
End Sub
|
|