Sub test()
Dim Arr, xD, Brr(), Crr(), T$, T1$, n%, n1%, i&, j%
Arr = Range([比對!a1], [比對!d65536].End(3))
Set xD = CreateObject("Scripting.Dictionary")
ReDim Brr(1 To UBound(Arr), 1 To 4)
ReDim Crr(1 To UBound(Arr), 1 To 4)
n = 1
For i = 2 To UBound(Arr)
If i = UBound(Arr) Then GoTo 99
If Arr(i, 1) <> "" And Arr(i + 1, 1) = "" Then
T = Arr(i, 1) & "_" & Arr(i, 3)
For i2 = i + 1 To UBound(Arr)
If Arr(i2, 4) <> "" Then
T1 = Arr(i2, 4) & "_" & Arr(i, 3)
If T = T1 Then
Brr(n, 1) = Arr(i, 1)
Brr(n, 3) = Arr(i, 3)
Brr(n + 1, 2) = Arr(i2, 2)
Brr(n + 1, 3) = Arr(i2, 3)
Brr(n + 1, 4) = Arr(i2, 4)
n = n + 2: xD(T1) = 1: Exit For
End If
Else
Exit For
End If
Next i2
End If
99: Next i
For i = 2 To UBound(Arr)
If Arr(i, 1) <> "" Then
T = Arr(i, 1) & "_" & Arr(i, 3)
Else
T = Arr(i, 4) & "_" & Arr(i, 3)
End If
If xD(T) <> 1 Then
n1 = n1 + 1
For j = 1 To 4: Crr(n1, j) = Arr(i, j): Next
End If
Next
Sheets("比對").[h2].Resize(n, 4) = Brr
Sheets("比對").[o2].Resize(n1, 4) = Crr
End Sub作者: sillykin 時間: 2021-8-26 21:31
Sub test()
Dim Arr, Brr(), Crr(), xD, xD1, T$, i&, n%, n1%
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
Arr = Range([人工名冊!a1], [人工名冊!c65536].End(3))
ReDim Brr(1 To UBound(Arr), 1 To 4) '相同
ReDim Crr(1 To UBound(Arr), 1 To 4) '不相同
For i = 2 To UBound(Arr)
T = Arr(i, 3) & "_" & Arr(i, 1)
xD(T) = Array(Arr(i, 1), Arr(i, 3))
Next
Arr = Range([會計名冊!a1], [會計名冊!c65536].End(3))
For i = 2 To UBound(Arr)
T = Arr(i, 2) & "_" & Arr(i, 3)
xD1(T) = Array(Arr(i, 1), Arr(i, 2), Arr(i, 3))
Next
For Each ky In xD
If xD1.Exists(ky) Then
n = n + 1: Brr(n, 1) = xD(ky)(0): Brr(n, 3) = xD(ky)(1)
n = n + 1: For j = 2 To 4: Brr(n, j) = xD1(ky)(j - 2): Next
Else
n1 = n1 + 1: Crr(n1, 1) = xD(ky)(0): Crr(n1, 3) = xD(ky)(1)
End If
Next
For Each ky In xD1
If Not xD.Exists(ky) Then
n1 = n1 + 1: For j = 2 To 4: Crr(n1, j) = xD1(ky)(j - 2): Next
End If
Next
With Sheets("比對")
If n > 0 Then '相同
.[v1:y1] = Array("日期", "統一編號", "戶名", "查詢日")
.[v2].Resize(n, 4) = Brr
End If
If n1 > 0 Then '不相同
.[aa1:ad1] = Array("日期", "統一編號", "戶名", "查詢日")
.[aa2].Resize(n1, 4) = Crr
End If
End With
End Sub作者: sillykin 時間: 2021-8-27 16:31