|
Dim i As Long, m As Long, a As Long, val As Long
Dim material As String, area As Range, ave As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.CutCopyMode = False
Sheets("需排产清单").Range("a2:m" & Sheets("需排产清单").Range("b2").CurrentRegion.Rows.count) = "" '将《需排产清单》A2~M(有填订单的行)区域清空
For i = 2 To Range("a1").CurrentRegion.Rows.count '《订单表》A2以后区域,表行标
material = Cells(i, 6) '对应《订单表》产品名称那一列
ave = Cells(i, 7) '对应《订单表》数量那一列
a = Sheets("需排产清单").Range("b1").CurrentRegion.Rows.count '《需排产清单》所有有内容的行数,开始值为1,只有一行
With Sheets("BOM").Range("a1")
.CurrentRegion.AutoFilter field:=1, Criteria1:=material '自动筛选BOM表A1单元格有内容区域,第一列(即产品名称列),筛选内容为《订单表》产品名称,第一个删选对象为F2
Set area = .CurrentRegion '设定area区域为筛选后的区域
area.Copy Sheets("需排产清单").Range("f" & a + 1) '复制area区域内容到《需排产清单》f(a+1),一开始为F2区域
Sheets("需排产清单").Range("i" & a + 2 & ":i" & Sheets("需排产清单").Range("b1").CurrentRegion.Rows.count).Insert Shift:=xlToRight
For m = a + 2 To Sheets("需排产清单").Range("b1").CurrentRegion.Rows.count
Sheets("需排产清单").Cells(m, 9) = Sheets("需排产清单").Cells(m, 8) * ave
Next
Sheets("需排产清单").Cells(a + 2, 2) = Sheets("订单表").Cells(i, 2)
Sheets("需排产清单").Cells(a + 2, 3) = Sheets("订单表").Cells(i, 3)
Sheets("需排产清单").Cells(a + 2, 4) = Sheets("订单表").Cells(i, 4)
Sheets("需排产清单").Cells(a + 2, 5) = Sheets("订单表").Cells(i, 5)
Sheets("需排产清单").Rows(a + 1).Delete
.CurrentRegion.AutoFilter
End With
Next
黄色底色标出的到底是指哪块区域,最后绿色底色标出的.CurrentRegion.AutoFilter填充哪里
|
|