各位前輩好
我的需求是要把WIP(Sheet)各製程的排程日期
整理到排程(sheet)裡
各製程的每日生產總量不固定
資料非常多
我的想法是比對排程裡的每日總數量
超過每日生產總量的話就順排至下一天
還要避開星期天
因為我只會用迴圈寫
一直順推
都會累積到某一天(例如圖一)
例:
排程(sheet)的01雷射清洗前_站
每日生產總量是2200
先依據WIP(sheet)DL欄位日期
把A欄_批號資料帶入對應的排程日期裡
帶入時比對已經排入的總數
超過的就被入隔天
程式如下
'01雷射清洗前
For j = 2 To r1
dl = Sheets("WIP").Range("dl" & j)
If dl <> "" Then
lot = Sheets("WIP").Range("a" & j)
'找製程別
Dim c As Range
Set c = Sheets("排程").Range("b:b")
fnd = c.Find(what:="01雷射清洗前", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
'
'找日期欄
Dim c1 As Range
Set c1 = Sheets("排程").Range("a1:cfm1")
fnd1 = c1.Find(what:=dl, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Column
'找日期列
Dim c2 As Range
Set c2 = Sheets("排程").Columns(fnd1)
fnd2 = c2.Find(what:="", after:=Cells(1, fnd1), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
plus = Cells(fnd, fnd1 - 2)
If plus < 2000 Then
Cells(fnd2, fnd1) = lot
plus1 = Cells(fnd, fnd1 + 7)
ElseIf plus1 < 2000 Then
Dim c3 As Range
Set c3 = Sheets("排程").Columns(fnd1 + 8)
fnd3 = c3.Find(what:="", after:=Cells(1, fnd1 + 8), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd3, fnd1 + 8) = lot
plus2 = Cells(fnd, fnd1 + 15)
ElseIf plus2 < 2000 Then
Dim c4 As Range
Set c4 = Sheets("排程").Columns(fnd1 + 16)
fnd4 = c4.Find(what:="", after:=Cells(1, fnd1 + 16), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd4, fnd1 + 16) = lot
plus3 = Cells(fnd, fnd1 + 23)
ElseIf plus3 < 2000 Then
Dim c5 As Range
Set c5 = Sheets("排程").Columns(fnd1 + 24)
fnd5 = c5.Find(what:="", after:=Cells(1, fnd1 + 24), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd5, fnd1 + 24) = lot
plus4 = Cells(fnd, fnd1 + 31)
ElseIf plus4 < 2000 Then
Dim c6 As Range
Set c6 = Sheets("排程").Columns(fnd1 + 32)
fnd6 = c6.Find(what:="", after:=Cells(1, fnd1 + 32), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd6, fnd1 + 32) = lot
plus5 = Cells(fnd, fnd1 + 39)
ElseIf plus5 < 2000 Then
Dim c7 As Range
Set c7 = Sheets("排程").Columns(fnd1 + 40)
fnd7 = c7.Find(what:="", after:=Cells(1, fnd1 + 40), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd7, fnd1 + 40) = lot
plus6 = Cells(fnd, fnd1 + 47)
ElseIf plus6 < 2000 Then
Dim c8 As Range
Set c8 = Sheets("排程").Columns(fnd1 + 48)
fnd8 = c8.Find(what:="", after:=Cells(1, fnd1 + 48), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd8, fnd1 + 48) = lot
Else
End If
End If
Next j
請各位幫幫忙了!!!!
搞不出來
會被老闆抓去埋
先謝謝前輩們的大恩大德 |