|
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("物料")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a2:e" & r)
- For i = 1 To UBound(brr)
- d(CStr(brr(i, 2))) = i
- Next
- End With
-
- With Worksheets("做单")
- r = .Columns("a:j").Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If Len(arr(i, 3)) = 0 Then
- For j = 1 To UBound(arr, 2)
- arr(i, j) = Empty
- Next
- Else
- If d.exists(CStr(arr(i, 3))) Then
- m = d(CStr(arr(i, 3)))
- arr(i, 6) = brr(m, 3)
- arr(i, 8) = brr(m, 4)
- arr(i, 10) = brr(m, 5)
- arr(i, 7) = arr(i, 5) * arr(i, 6)
- End If
- End If
- Next
- Application.EnableEvents = False
- .Range("a2:j" & r) = arr
- Application.EnableEvents = True
- End With
- End Sub
复制代码 |
|