|
Public Sub dsm_2()
'找出相同数据并删除,将找不到的单号,或者是单号一致数据不一致的提取到另一个表格
Dim m As Integer, n As Integer, r1 As Integer, r2 As Integer
Dim Arr(), Brr(), Crr(), Drr(), r%, ra%
Dim ds As Object
Set ds = CreateObject("Scripting.Dictionary")
r1 = Range("b65536").End(xlUp).Row
r2 = Range("i65536").End(xlUp).Row
Arr = Range("a3:d" & r1).Value
Brr = Range("h3:k" & r2).Value
For n = 1 To r1 - 2
ds(Arr(n, 2)) = n
Next
ReDim Crr(1 To r2 - 2, 1 To 8), Drr(1 To r1 - 2, 1 To 4)
For m = 1 To r2 - 2
If ds.exists(Brr(m, 2)) Then
n = ds(Brr(m, 2))
If Arr(n, 1) = Brr(m, 1) And Arr(n, 3) = Brr(m, 3) Then
Arr(n, 1) = "": Arr(n, 3) = ""
Else
r = r + 1
If Arr(n, 1) <> "" Then ra = ra + 1
For i = 1 To 4
Crr(r, i) = Brr(m, i)
If Arr(n, 1) <> "" Then
Crr(r, i + 4) = Arr(n, i)
Drr(ra, i) = Arr(n, i)
End If
Next
End If
Else
r = r + 1
For i = 1 To 4
Crr(r, i) = Brr(m, i)
Next
End If
Next
For n = 1 To r1 - 2
If Arr(n, 1) <> "" Then
ra = ra + 1
For i = 1 To 4
Drr(ra, i) = Arr(n, i)
Next
End If
Next
Application.EnableEvents = False
Application.ScreenUpdating = False
Range("l2:n2").Value = Range("a2:c2").Value
Range("a3:d" & r1).Value = Drr
Range("h3:o" & r2).Value = Crr
Range("l2:o" & r + 2).Borders.LineStyle = 1
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
|
|