|
《原始数据区》(特征1&特征2),匹配《标准件》里面的K列&M列,如果相同,判断1,《原始数据》库存数>《标准件》数量;判断2,《原始数据》长度>《标准件》长度,把《原始数据》代码,填写到D列。同时《原始数据》库存数-《标准件》数量,再返回《原始数据》N列。
编写目的:用原始数据区库存零件,长改短后,使用。同时把改造的库存数更新。
文件里面代码是VB6代码。
遇到的问题是,标准件里面填写的改造数量<库存数减去的数量。感觉是字典重新赋值的时候,重复扣减了。找不到原因。
- Sub 匹配()
- Dim ar, arr, I, J, R1, Y1, S
- Set XL = GetObject(, "Excel.Application")
- Set XLB = XL.Workbooks("清单工具.XLSX")
- Set XLS = XLB.Worksheets("原始数据区")
- Set XLSB = XLB.Worksheets("标准件")
- RR1 = XLS.[C65536].End(xlUp).Row
- arr = XLS.Range("A1:z" & RR1)
- R1 = XLSB.[C65536].End(xlUp).Row
- ar = XLSB.Range("A1:AJ" & R1)
- XL.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- For I = 1 To UBound(arr)
- KM = arr(I, 3) & "|" & arr(I, 10) & arr(I, 12) & "|" & arr(I, 11)
- d(KM) = arr(I, 13)
- Next I
- K = d.KEYS
- For I = 2 To R1
- BM = ar(I, 11) & ar(I, 13)
- BC = ar(I, 12)
- BS = ar(I, 6)
- For S = 0 To UBound(K)
- t = Split(K(S), "|")
- If ar(I, 13) = "普通模板" And IsEmpty(ar(I, 5)) Then '---------------------------------普板----------------------------------------------------1
- If BC <= 1100 Then '------------------------------------------------1100以内不能拼接----------------------2
- If t(1) = BM Then '------------------------匹配字典----------------------------------------3
- NU = d((K(S)))
- If NU > BS Then '-----------------------------库存数大于改制数------------------4
- If t(2) - BC < 50 And t(2) - BC > 0 Then '-------------去50以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS
- d(K(S)) = NU - BS '字典库存-出库数
- ElseIf t(2) - BC >= 50 And t(2) - BC < 100 Then '--------去100以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS
- d(K(S)) = NU - BS '字典库存-出库数
- ElseIf t(2) - BC >= 100 And t(2) - BC < 150 Then '-------去150以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS
- d(K(S)) = NU - BS '字典库存-出库数
- ElseIf t(2) - BC >= 150 And t(2) - BC < 200 Then '-------去200以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS
- d(K(S)) = NU - BS '字典库存-出库数
- End If
- ElseIf NU > BS * 2 Then '--------------------库存数大于改制数*2----------------4
- If t(2) - BC * 2 < 100 And t(2) - BC >= 50 Then '-----------去100以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS / 2
- d(K(S)) = NU - BS / 2 '字典库存-出库数
- ElseIf t(2) - BC * 2 < 150 And t(2) - BC >= 100 Then '------去150以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS / 2
- d(K(S)) = NU - BS / 2 '字典库存-出库数
- ElseIf t(2) - BC * 2 < 200 And t(2) - BC >= 150 Then '------去200以内---5
- XLSB.Cells(I, 4) = t(0)
- XLSB.Cells(I, 5) = BS / 2
- d(K(S)) = NU - BS / 2 '字典库存-出库数
- End If
- End If '------------------------------------------------------------4
- End If '--------------------------------------------------------------------3
- End If '------------------------------------------------------------------------------2
- End If
- Next
- Next
- For J = 1 To RR1
- If d.Exists(arr(J, 3) & "|" & arr(J, 10) & arr(J, 12) & "|" & arr(J, 11)) Then
- t = d(arr(J, 3) & "|" & arr(J, 10) & arr(J, 12) & "|" & arr(J, 11))
- XLS.Cells(J, 14) = t
- End If
- Next J
- Set d = Nothing
- XL.ScreenUpdating = True
- Set XL = Nothing
- Set XLB = Nothing
- Set XLS = Nothing
- Erase arr
- Erase ar
- End Sub
复制代码
|
|