|
Sub TEST()
Dim i As Long, j As Long, MyR As Long, MyC As Integer
Range("g4:s" & Cells(65536, 7).End(3).Row).ClearContents
MyR = 4
MyC = 7
With Sheets("BOM表")
For i = 4 To Cells(65536, 2).End(3).Row
For j = 3 To .Cells(65536, 1).End(xlUp).Row
If Cells(i, 2) = .Cells(j, 1) Then
Cells(MyR, MyC) = .Cells(j, 1) '成品代码
Cells(MyR, MyC + 1) = .Cells(j, 2) '物料名称
Cells(MyR, MyC + 2) = .Cells(j, 3) '规格
Cells(MyR, MyC + 3) = .Cells(j, 4) '单位
Cells(MyR, MyC + 4) = .Cells(j, 5) '单位
Cells(MyR, MyC + 5) = Cells(MyR, MyC + 4) * Cells(i, 4) '领料
Cells(MyR, MyC + 6) = .Cells(j, 6) '备注
MyR = MyR + 1 '增加一行输入
If MyR > 65536 Then '判断是否表格最后一行,是则开启下一系列
MyR = 4
MyC = MyC + 7
End If
End If
Next j
Next i
End With
End Sub
由于时间关系没有设计完善,还有就是,既然用VBA了,表格里就尽量不要加公式,因为公式自动运算,会减慢运算速度。 |
|