- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 61
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-3-12
               
|
本帖最後由 Hsieh 於 2013-1-12 00:10 編輯
回復 8# adam2010
Sheets("交期")的D欄數量是人工先輸入好的嗎?
試試看- Sub ex()
- Dim Ar(), Ay(), C As Range, Rng As Range
- Set d = CreateObject("Scripting.Dictionary") '數量
- Set d1 = CreateObject("Scripting.Dictionary") '日期
- With Sheets("出貨日")
- For Each a In .Range(.[A2], .[A2].End(xlDown)) '物料
- Set Rng = a.EntireRow.SpecialCells(xlCellTypeConstants, xlNumbers) '訂貨
- ReDim Preserve Ar(s) '數量
- ReDim Preserve Ay(s) '日期
- Ar(s) = 0
- Ay(s) = .Cells(1, Rng.Column)
- s = s + 1
- For Each C In Rng
- cnt = cnt + C
- ReDim Preserve Ar(s)
- ReDim Preserve Ay(s)
- Ar(s) = cnt
- Ay(s) = .Cells(1, C.Column).Value
- s = s + 1
- Next
- d(a.Value) = Ar
- d1(a.Value) = Ay
- Erase Ar: Erase Ay: s = 0: cnt = 0
- Next
- End With
- With Sheets("交期")
- For Each a In .Range(.[A2], .[A2].End(xlDown))
- cnt = cnt + a.Offset(, 3)
- If cnt <= Application.Max(d(a.Value)) Or cnt - a.Offset(, 3) < Application.Max(d(a.Value)) Then _
- a.Offset(, 4) = Application.Lookup(cnt, d(a.Value), d1(a.Value)) _
- Else a.Offset(, 4) = "NA"
- If a <> a.Offset(1) Then cnt = 0
- Next
- End With
- End Sub
複製代碼 |
|