紅字修正
Sub TEST()
Dim Arr, Brr, xD, i&, j&, R&, C&, U&, T$
Sheets("總表").Select
Columns("A:E").Clear
Set xD = CreateObject("Scripting.Dictionary")
ReDim Brr(1 To 2000, 1 To 99)
Brr(1, 1) = "號碼"
For i = 1 To Sheets.Count
If Left(Sheets(i).Name, 1) <> "X" Then GoTo i99
C = C + 1: Brr(1, C + 1) = Sheets(i).Name
Arr = Sheets(i).UsedRange
For j = 2 To UBound(Arr)
T = Arr(j, 1): If T = "" Then GoTo j99
U = xD(T)
If U = 0 Then R = R + 1: U = R: xD(T) = R: Brr(U + 1, 1) = T
Brr(U + 1, C + 1) = Brr(U + 1, C + 1) + Arr(j, 2)
j99: Next j
i99: Next i
With Sheets("總表").[a1].Resize(R + 1, C + 2)
.Columns(1).NumberFormatLocal = "@"
.Value = Brr
.Sort Key1:=.Item(1), Order1:=xlAscending, Header:=xlYes
.Columns(C + 2) = "=SUM(RC[-" & C & "]:RC[-1])"
.Rows(R + 2) = "=n(SUM(R[-" & R & "]C:R[-1]C))"
.Cells(1, C + 2) = "合計": .Cells(R + 2, 1) = "合計"
Union(.Rows(1), .Rows(R + 2), .Columns(C + 2)).Font.Bold = True
End With
End Sub作者: gaishutsusuru 時間: 2020-10-14 20:07