|
本帖最后由 军生 于 2022-11-18 22:03 编辑
test1与test2VBA合并
Sub test1()
Cells.Select
Worksheets("出荷扫描查询").Range("$A$1:$O$10000").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6 _
, 7, 8, 9, 10, 11, 12, 13, 14, 15), Header:=xlYes
End Sub
Sub test2()
Dim r%, i%
Dim arr, brr
Dim d As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
With Worksheets("出荷扫描查询")
.AutoFilterMode = False
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:o" & r)
For i = 1 To UBound(arr)
xm = Left(arr(i, 9), 6) & "+" & Right(arr(i, 1), 2)
If Not d.exists(xm) Then
Set d(xm) = CreateObject("scripting.dictionary")
End If
d(xm)(arr(i, 6)) = d(xm)(arr(i, 6)) + Val(arr(i, 8))
Next
End With
With Worksheets("南北库打印签收单")
cs = Replace(.Range("e5"), "J", "3")
.Range("o11:o20") = Empty
arr = .Range("a11:q20")
For i = 1 To UBound(arr)
If arr(i, 9) * arr(i, 10) <> arr(i, 11) Then
If Len(arr(i, 2)) <> 0 Then
pf = Left(arr(i, 2), 6)
xm = pf & "+" & Format(cs, "00")
d1.RemoveAll
If d.exists(xm) Then
For Each bb In d(xm).keys
d1(d(xm)(bb)) = d1(d(xm)(bb)) + 1
Next
ss = ""
For Each bb In d1.keys
ss = ss & "+" & bb & "*" & d1(bb)
Next
arr(i, 15) = Mid(ss, 2)
End If
End If
End If
Next
.Range("o11").Resize(UBound(arr), 1) = Application.Index(arr, 0, 15)
End With
End Sub
|
|