Sub test()
Dim Arr, xD, T$, i&, j%
Set xD = CreateObject("Scripting.Dictionary")
For Each sh In Sheets
If InStr(sh.Name, "專案") Then
With sh
Arr = .[a1].CurrentRegion
For i = 5 To UBound(Arr)
If Arr(i, 3) = "" Then GoTo 90
T = sh.Name & "|" & Arr(i, 1)
xD(T) = Arr(i, 3)
90: Next
End With
End If
Next
With Sheets(1)
[b5:f58] = ""
Arr = .[a1].CurrentRegion
For i = 5 To UBound(Arr): For j = 2 To UBound(Arr, 2)
T = Arr(4, j) & "|" & Arr(i, 1)
Arr(i, j) = xD(T)
Next: Next
.[a1].Resize(UBound(Arr), UBound(Arr, 2)) = Arr
End With
End Sub作者: waitto04 時間: 2022-5-29 09:59
Sub test()
Dim Arr, xD, T$, i&, j%
Set xD = CreateObject("Scripting.Dictionary")
For Each sh In Sheets
If InStr(sh.Name, "專案") Then '工作名稱有專案
With sh
Arr = .[a1].CurrentRegion '資料裝入數組
For i = 5 To UBound(Arr)
If Arr(i, 3) = "" Then GoTo 90 '沒數據離開
T = sh.Name & "|" & Arr(i, 1) '條件:工作表名稱+項目
xD(T) = Arr(i, 3) '數據裝入字典
90: Next
End With
End If
Next
With Sheets(1)
.[b5:f58] = "" '清除原有數據資料,前面原來漏掉 . ,請自行修改
Arr = .[a1].CurrentRegion '資料裝入數組
For i = 5 To UBound(Arr): For j = 2 To UBound(Arr, 2)
T = Arr(4, j) & "|" & Arr(i, 1) '條件:工作表名稱+項目
Arr(i, j) = xD(T) '匯出字典數據
Next: Next
.[a1].Resize(UBound(Arr), UBound(Arr, 2)) = Arr '數據回填到excel
End With
End Sub作者: waitto04 時間: 2022-5-29 11:11