|
Sub paichan()
Dim ar As Variant
Dim br()
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("订单")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("j1:j" & rs) = Empty
ar = .Range("a1:j" & rs)
ReDim br(1 To UBound(ar), 1 To 4)
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
If Trim(ar(i, 9)) = "" Then
d(Trim(ar(i, 3))) = ""
End If
End If
Next i
If d.Count = 0 Then MsgBox "没有需要安排的数据": Exit Sub
For Each k In d.keys
m = m + 1
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) = k Then
If Trim(ar(i, 9)) = "" Then
ar(i, 9) = Format(ar(i, 2), "yyyymmdd") & Format(m, "000")
ar(i, 10) = "新"
End If
End If
Next i
Next k
.[i1].Resize(UBound(ar), 1) = Application.Index(ar, 0, 9)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" And Trim(ar(i, 10)) = "新" Then
t = dc(Trim(ar(i, 3)))
If t = "" Then
kk = kk + 1
dc(Trim(ar(i, 3))) = kk
t = kk
br(kk, 1) = ar(i, 9)
br(kk, 2) = ar(i, 2)
br(kk, 3) = ar(i, 3)
End If
br(t, 4) = br(t, 4) + ar(i, 4)
End If
Next i
With Sheets("生产计划")
r = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(r, 1).Resize(kk, 4) = br
End With
MsgBox "ok!"
End Sub
|
|