各位前輩好
我的需求是要把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
'01雷射清洗前
For j = 2 To r1
dl = Sheets("WIP").Range("dl" & j)
If dl <> "" Then
lot = Sheets("WIP").Range("a" & j)
Wip = Sheets("WIP").Range("k" & 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 '總量<2000排入行程
Cells(fnd2, fnd1) = lot
Cells(fnd2, fnd1).Offset(, 2) = Wip 'lot的數量
Else
For x = 6 To (Cells(2, fnd1).End(2).Column - fnd1) Step 8 '判斷其他日期的總量
If Cells(Fnd, fnd1).Offset(, x) < 2000 And Cells(Fnd, fnd1).Offset(-2, (x + 3)) <> "日" Then '排除"日",判斷其他工作日的總量<2000
Dim c3 As Range
Set c3 = Sheets("排程").Columns(fnd1 + (x + 2))
fnd3 = c3.Find(what:="", after:=Cells(1, fnd1 + (x + 2)), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd3, fnd1).Offset(, (x + 2)) = lot
Cells(fnd3, fnd1).Offset(, (x + 4)) = Wip
Exit For
End If
Next
End If
End If
Next j
End Sub作者: 52ee24 時間: 2020-5-14 10:44
謝謝 jcchiang
可以跑了!!
另外請問我要複製程式
向下尋找別的製程
但一直貼錯
找不到下個製程的列數
我把變數都增加"02"
這樣哪裡錯了
麻煩幫忙
謝謝你
'02雷射篩孔後
For i = 2 To r1
dm = Sheets("WIP").Range("dm" & i)
If dm <> "" Then
lot02 = Sheets("WIP").Range("a" & i)
Wip02 = Sheets("WIP").Range("k" & i) Dim c02 As Range
Set c02 = Sheets("??{").Range("b:b")
Fnd02 = c02.Find(what:="02雷射篩孔後", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Dim c102 As Range
Set c102 = Sheets("??{").Range("a1:cfm1")
fnd102 = c102.Find(what:=dm, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Column
Dim c202 As Range
Set c202 = Sheets("排程").Columns(fnd102)
fnd202 = c202.Find(what:="", after:=Cells(1, fnd102), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
plus02 = Cells(Fnd02, fnd102 - 2)
If plus02 < 2000 Then
Cells(fnd202, fnd102) = lot02
Cells(fnd202, fnd102).Offset(, 2) = Wip02
Else
For x = 6 To (Cells(2, fnd102).End(2).Column - fnd102) Step 8
If Cells(Fnd02, fnd102).Offset(, x) < 2000 And Cells(Fnd02, fnd102).Offset(-2, (x + 3)) <> "日" Then
Dim c302 As Range
Set c302 = Sheets("排程").Columns(fnd102 + (x + 2))
fnd302 = c302.Find(what:="", after:=Cells(1, fnd102 + (x + 2)), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Row
Cells(fnd302, fnd102).Offset(, (x + 2)) = lot02
Cells(fnd302, fnd102).Offset(, (x + 4)) = Wip02
Exit For
End If
Next
End If
End If
Next i作者: 52ee24 時間: 2020-5-15 21:19