|
小白求问,这三个地方的判断代码如何更改
-
- 'excel生产排程,多设备,多产品,多班次,不同产能都能实现
- '2011-7-18
- Sub calc()
- Dim plancount As Double '计划数量
- Dim calccount As Double '合计数量
- Dim diffcount As Double '差异
- Dim machcount As Double '日产能
- Dim odrcount As Double '订单重量
- Dim odrdiff As Double '订单差异
- Dim workclass As Double '工作班次
- Dim odrsum As Double '订单合计
- Application.ScreenUpdating = False
-
- Range("U18") = Range("u1")
-
- a = Range("iv2").End(xlToLeft).Column '至班次最后一格(第二行,横向)
- b = Range("O65536").End(xlUp).Row '至产线最后一行(E行,竖向)
- Range("U19:iv" & b).ClearContents '清除原计划数量
- Range("U19:iv" & b).Interior.ColorIndex = xlNone
- Range("a19:a" & b).ClearContents '清除原交期
- Range("U3:iv3").ClearContents
-
- Dim beginrow As Integer
- Dim begincol As Integer
-
- c = 19
- beginrow = 19
- begincol = 21
-
- If Cells(19, 10) <> "" Then '如果填写实际生产日期,则按实际生产日期重新排序
- Range("A19:CT" & b & "").Sort Key1:=Range("J19"), Order1:=xlAscending, Header:=xlGuess, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
- :=xlPinYin, DataOption1:=xlSortNormal
- End If
-
- If Cells(19, 10) <> "" And Cells(i + 1, 15) <> "" Then '第一次判断.根据实际开始日期 还是默认开始日期
- begincol = Cells(19, 13)
- End If
- For j = begincol To a '第一层循环:是从11到 班次最后一格(横向 循环)
- calccount = 0 '合计数量
-
- For i = c To b '第二层循环:是从K9到 K+有数据的最后一格(竖向 循环)
- If i <> 19 Then
- '重新计算当天相同产线的已用工时
- Cells(3, j).FormulaArray = "=SUM(R19C" & j & ":R" & i - 1 & "C" & j & "/R19C16:R" & i - 1 & "C16*IF(R" & i & "C15=R19C15:R" & i - 1 & "C15,1))"
- End If
- '这段代码也可用来计算已用工时 数据量大的话效率很低
- ' For k = 19 To i
- ' If k <> i And Cells(k, 15) = Cells(i, 15) Then
- ' Cells(3, j) = Cells(k, j) / Cells(k, 16) + Cells(3, j)
- ' End If
- ' Next
- workclass = Cells(4, j) '工作时间
- machcount = Cells(i, 16) '产能
- plancount = workclass * machcount '计划数量='工作时间*'日产能
- diffcount = plancount - calccount '差异=计划数量-合计数量
- odrdiff = Cells(i, 20) * -1 '订单差异=J+当前行号
-
- If odrdiff <= diffcount Then '如: 订单差异<='差异 那么:
- Cells(i, j) = odrdiff '当班计划数=订单差异
- Cells(i, 1) = Cells(18, j) '预计交期=当前完成日期
- Cells(3, j) = odrdiff / machcount '计算使用时间
- Cells(i, j).Interior.ColorIndex = 6
- '处理值为0的单元格
- ' If Cells(i, j).Value = 0 Then
- ' Cells(i, j).Value = ""
- ' Cells(i, j).Interior.ColorIndex = xlNone
- ' End If
- Else '如: 订单差异>差异 那么:
-
- Cells(i, j) = diffcount '当班计划数=差异
- Cells(i, j).Interior.ColorIndex = 6
- If diffcount < 0 Then '+---如果差异<0
- 'Cells(i, j) = 0
- Cells(i, j) = Int((1 - Cells(i - 1, j) / (Cells(2, j) * Cells(i - 1, 16))) * (Cells(2, j) * Cells(i, 16)))
- If Cells(i, j) >= odrdiff Then
- Cells(i, j) = odrdiff
- End If
- End If
- Cells(i, 1) = Cells(18, j) '预计交期=当前完成日期
- Cells(3, j) = Cells(3, j) + Cells(i, j) / machcount
- Cells(i, j).Interior.ColorIndex = 6 '当班计划数=差异
- calccount = 0 '合计数量
- c = i
- '处理值为0的单元格
- ' If Cells(i, j).Value = 0 Then
- ' Cells(i, j).Value = ""
- ' Cells(i, j).Interior.ColorIndex = xlNone
- ' End If
-
- Exit For '退出竖向循环,继续横向循环
- End If
-
-
- If Cells(i, 15) <> Cells(i + 1, 15) Then '如果: 产线号不同,那么:
-
-
- If Cells(19, 10) <> "" And Cells(i + 1, 15) <> "" Then '第二处判断 根据实际开始日期 还是默认开始日期
- begincol = Cells(i + 1, 13)
- End If
-
- j = begincol '从第一行开始算计划数
- calccount = 0 '合计数量归0
- Range("o3:iv3").ClearContents
- End If
- Next
-
- If Cells(i + 1, 15) = "" And Cells(i, 20) = 0 Then '判断最后一个产片的计算
- Exit For
- End If
-
- If j = a Then
- j = begincol - 1
-
- Range("o3:iv3").ClearContents
- calccount = 0
-
- For abc = i To 69
- If Cells(i, 15) = Cells(i + 1, 15) Then '如果: 产线号同,那么:
-
- i = i + 1
- ElseIf Cells(i, 15) <> Cells(i + 1, 15) Then
- 'j = j + 1
-
- End If
- Next
-
- c = i + 1
- End If
- If Cells(19, 10) <> "" And Cells(i + 1, 15) <> "" Then '第三处判断 .根据实际开始日期 还是默认开始日期
- begincol = Cells(i + 1, 13)
- End If
- Next
- Dim rng As Range
- '处理值为0的单元格
- ' For Each rng In Range(Cells(22, 21), Cells(b, a))
- ' If rng.Value = 0 Then
- ' rng.Value = ""
- ' rng.Interior.ColorIndex = xlNone
- ' End If
- ' Next
- Application.ScreenUpdating = True
- End Sub
- Sub cl()
- a = Range("iv2").End(xlToLeft).Column '至班次最后一格(第二行,横向)
- b = Range("O65536").End(xlUp).Row '至产线最后一行(E行,竖向)
- Range("U19:iv" & b).ClearContents '清除原计划数量
- Range("U19:iv" & b).Interior.ColorIndex = xlNone
- Range("a19:a" & b).ClearContents '清除原交期
- Range("U3:iv3").ClearContents
- End Sub
-
复制代码 |
|