因為資料的欄位不一致,只能用比對的
Sub ex()
Dim arr As Variant
Dim x%, y%, b%, a As Object
ReDim arr(Sheets.Count - 2, Sheets("summary").[a1].End(2).Column)
For x = 2 To Sheets.Count
arr(x - 2, 0) = x - 1
arr(x - 2, 1) = Sheets(x).Name
For Each a In Sheets("SUMMARY").Range([c1], [c1].End(2))
For b = 1 To 3 Step 2
For y = 1 To Sheets(x).Cells(65535, b).End(3).Row
If Left(Sheets(x).Cells(y, b), Len(a)) = a Then
arr(x - 2, a.Column - 1) = Sheets(x).Cells(y, b).Offset(, 1).Value
GoTo line1
End If
Next
Next
line1:
Next
Next
Sheets("SUMMARY").[a2].Resize(UBound(arr) + 1, UBound(arr, 2)) = arr
End Sub作者: mdr0465 時間: 2021-2-21 11:48