Sub test()
Dim Arr, Ar, Brr(1 To 10000, 1 To 4), xD, T, i&, j%, n%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([查詢!K1], [查詢!A65536].End(3))
For i = 2 To UBound(Arr)
For j = 2 To UBound(Arr, 2)
If Arr(i, j) <> "" Then Ar = Ar & "," & Arr(i, j)
Next
xD(Arr(i, 1) & "") = Mid(Ar, 2): Ar = ""
Next
Arr = Range([查詢2!B1], [查詢2!A65536].End(3))
For i = 2 To UBound(Arr): xD(Arr(i, 1) & "") = Arr(i, 2): Next
Arr = Range([資料!A3], [資料!B65536].End(3))
For i = 2 To UBound(Arr)
T = Arr(i, 1): n = n + 1
If xD.Exists(T & "") Then
Brr(n, 1) = T: Brr(n, 2) = Arr(i, 2)
Ar = Split(xD(T & ""), ",")
For j = 0 To UBound(Ar)
n = n + 1: Brr(n, 3) = Ar(j)
Brr(n, 4) = xD(Brr(n, 3) & "")
Next
Else
Brr(n, 1) = T: Brr(n, 2) = Arr(i, 2)
End If
Next
Sheets("結果").Range("A2").Resize(n, 4) = Brr
End Sub作者: qaqa3296 時間: 2021-7-5 21:04
Sub test2()
Dim Arr, Ar, Brr(1 To 10000, 1 To 4), xD, T, i&, j%, n%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([查詢!K1], [查詢!A65536].End(3))
For i = 2 To UBound(Arr)
For j = 2 To UBound(Arr, 2)
If Arr(i, j) <> "" Then Ar = Ar & "," & Arr(i, j)
Next
xD(Arr(i, 1) & "") = Mid(Ar, 2): Ar = ""
Next
Arr = Range([查詢2!B1], [查詢2!A65536].End(3))
For i = 2 To UBound(Arr): xD(Arr(i, 1) & "") = Arr(i, 2): Next
Arr = Range([資料!A1], [資料!B65536].End(3))
For i = 2 To UBound(Arr)
T = Arr(i, 1): n = n + 1
If xD.Exists(T & "") Then
Brr(n, 1) = T: Brr(n, 2) = Arr(i, 2)
Ar = Split(xD(T & ""), ",")
For j = 0 To UBound(Ar)
n = n + 1: Brr(n, 3) = Ar(j)
Brr(n, 4) = xD(Brr(n, 3) & "")
Next
Else
Brr(n, 1) = T: Brr(n, 2) = Arr(i, 2)
End If
Next
Sheets("結果").Range("A2").Resize(n, 4) = Brr
End Sub作者: qaqa3296 時間: 2021-7-5 21:55
Option Explicit
Sub TEST_1()
Dim Brr, Crr(1 To 100, 1 To 4), Y, T$, R&, i&, j%, Sh(4)
Set Y = CreateObject("Scripting.Dictionary")
For i = 1 To 4: Set Sh(i) = Sheets(i): Next
Brr = Range(Sh(2).[K2], Sh(2).[A65536].End(3))
For i = 1 To UBound(Brr): Y(Brr(i, 1)) = i: Next: Sh(2) = Brr
Brr = Range(Sh(3).[B2], Sh(3).[A65536].End(3))
For i = 1 To UBound(Brr): Y(Brr(i, 1) & "") = Brr(i, 2): Next
Brr = Range(Sh(1).[B2], Sh(1).[A65536].End(3))
For i = 1 To UBound(Brr)
R = R + 1: T = Brr(i, 1): Crr(R, 1) = T: Crr(R, 2) = Brr(i, 2)
For j = 2 To 255
If Sh(2)(Y(T), j) = "" Then Exit For Else: R = R + 1
Crr(R, 3) = Sh(2)(Y(T), j): Crr(R, 4) = Y(Crr(R, 3) & "")
Next
Next
Sh(4).[A2].Resize(R, 4) = Crr
Set Y = Nothing: Erase Brr, Crr, Sh
End Sub