|
- Private Sub CommandButton1_Click()
- t = Timer
- With Sheets("生产计划")
- 生产计划 = .Range(.UsedRange.Address)
- End With
- With Sheets("基准表")
- 基准表 = .Range(.UsedRange.Address)
- End With
- Dim 半成1 As Range, 部门1 As Range, 半成2 As Range, 耗材1 As Range, 单耗1 As Range
- Dim r半成 As Long, r部门 As Long, c半成 As Long, c部门 As Long, r半成2 As Long, r耗材 As Long, r单耗 As Long, c半成2 As Long, c耗材 As Long, c单耗 As Long, kk As Long, k As Long, i As Long, ii As Long, ooo As Long, iii As Long
- Set 半成1 = Sheets("生产计划").Range("1:5").Find("半成品")
- Set 部门1 = Sheets("生产计划").Range("1:5").Find("部门名称")
- Set 半成2 = Sheets("基准表").Range("1:5").Find("半成品")
- Set 耗材1 = Sheets("基准表").Range("1:5").Find("耗材料号")
- Set 单耗1 = Sheets("基准表").Range("1:5").Find("单耗")
- If Not 半成1 Is Nothing Or Not 部门1 Is Nothing Or Not 半成2 Is Nothing Or Not 耗材1 Is Nothing Or Not 单耗1 Is Nothing Then
- r半成 = 半成1.Row
- r部门 = 部门1.Row
- If r半成 = r部门 Then
- c半成 = 半成1.Column
- c部门 = 部门1.Column
- Else
- MsgBox "请检 生产计划中的1到5行中是否存在半成品》部门名称 "
- Exit Sub
- End If
- r半成2 = 半成2.Row
- r耗材 = 耗材1.Row
- r单耗 = 单耗1.Row
- If r半成2 = r耗材 And r耗材 = r单耗 Then
- c半成2 = 半成2.Column
- c耗材 = 耗材1.Column
- c单耗 = 单耗1.Column
- Else
- MsgBox "请检查 基准表 中的1到5行中是否存在 半成品》》耗材料号 》单耗字段"
- Exit Sub
- End If
- End If
- For oo = 1 To UBound(生产计划, 2)
- If IsDate(生产计划(r半成, oo)) Then
- k = k + 1
- Sheets("标准用量").Cells(2, 7 + k) = 生产计划(r半成, oo)
- End If
- Next
- For ooo = 1 To UBound(生产计划, 2)
- If IsDate(生产计划(r半成, ooo)) Then
- ooo = ooo - 1
- GoTo 11
- End If
- Next
- 11:
- ReDim 标准用量(1 To UBound(生产计划, 1), 1 To 7 + k)
- For i = r半成 + 1 To UBound(生产计划, 1)
- 标准用量(i - 2, 2) = 生产计划(i, c部门)
- 标准用量(i - 2, 3) = 生产计划(i, c半成)
- 标准用量(i - 2, 1) = "检查基准表"
- For ii = r半成2 + 1 To UBound(基准表, 1)
- If 生产计划(i, c半成) = 基准表(ii, c半成2) Then
- 标准用量(i - 2, 1) = 基准表(ii, c耗材)
- For iii = 1 To k
- 标准用量(i - 2, 7 + iii) = 基准表(ii, c单耗) * 生产计划(i, ooo + iii)
- Next iii
- GoTo 111
- End If
- Next
- 111:
- Next
- Sheets("标准用量").Cells(2, 1).Resize(UBound(标准用量), UBound(标准用量, 2)).Borders.LineStyle = xlContinuous
- Sheets("标准用量").Cells(3, 1).Resize(UBound(标准用量), UBound(标准用量, 2)) = 标准用量
- Sheets("标准用量").Cells(3, 1).Resize(UBound(标准用量), UBound(标准用量, 2)) = 标准用量
- t = Timer - t
- MsgBox "耗时" & t
- End Sub
复制代码 |
|