Sub test()
Dim i%, r%
Dim arr, brr
Dim d As Object
Dim d1 As Object
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
Dim ws As Worksheet
m = 1
For Each ws In Worksheets
If ws.Name <> "匯總" Then
With ws
r = .Cells(.Rows.Count, 1).End(xlUp).Row
c = .Cells(1, .Columns.Count).End(xlToLeft).Column
arr = .Range("a1").Resize(r, c)
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 1)) Then
ReDim brr(1 To 100)
brr(1) = arr(i, 1)
Else
brr = d(arr(i, 1))
End If
For j = 2 To UBound(arr, 2)
If Not d1.exists(arr(1, j)) Then
m = m + 1
d1(arr(1, j)) = m
End If
→出錯行brr(d1(arr(1, j))) = brr(d1(arr(1, j))) + arr(i, j)
Next
d(arr(i, 1)) = brr
Next
End With
End If
Next
With Worksheets("匯總")
.Cells.Clear
.Range("a1") = "國家"
.Range("b1").Resize(1, d1.Count) = d1.keys
.Range("a2").Resize(d.Count, 100) = Application.Transpose(Application.Transpose(d.items))
r = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("a1").Resize(r, d1.Count + 1).Borders.LineStyle = xlContinuous
End With
End Sub