Option Explicit
Sub 統計各日期_各公司人數_排除重複_1()
Dim i&, u&, C&, R&, v&, Shr&, T2$, T4$, T6$, TT$
Dim Arr, Crr, Y, Z, xR, Sh1, Sh2, Sha
Set Z = CreateObject("Scripting.Dictionary")
Set Y = CreateObject("Scripting.Dictionary")
Set Sh1 = Sheets("資料庫")
Set Sh2 = Sheets("總表單")
Set Sha = Sh1.Range("A3:G" & Split(Sh1.UsedRange.Address, "$")(4))
Shr = Sha.Rows.Count
Sha.Copy Sh2.[A1]
Sha.Offset(, 8).Copy Sh2.Cells(Shr + 1, 1)
With Sh2.UsedRange
.Replace What:=" ", Replacement:="", LookAt:=xlPart
.Sort _
KEY1:=.Item(6), Order1:=xlAscending, _
Key2:=.Item(2), Order2:=xlAscending, _
Header:=xlNo, Orientation:=xlTopToBottom
Arr = .Value
.EntireRow.Delete
End With
For i = 1 To UBound(Arr)
If Not Z.Exists(Arr(i, 6)) And Arr(i, 6) <> "" Then
Z(Arr(i, 6)) = Z.Count + 1
End If
If Not Y.Exists(Arr(i, 2)) And Arr(i, 2) <> "" Then
Y(Arr(i, 2)) = Y.Count + 1
End If
Next
R = Z.Count
Sh2.[A2].Resize(R, 1) = Application.Transpose(Z.KEYS)
C = Y.Count
Sh2.[B1].Resize(1, C) = Y.KEYS
ReDim Crr(R, C)
For i = 1 To UBound(Arr)
T2 = Arr(i, 2)
T4 = Trim(Arr(i, 4))
T6 = Trim(Arr(i, 6))
TT = T2 & "|" & T4 & "|" & T6 & "|"
If Y.Exists(TT) Then GoTo PP
If Y(T2) <> "" And Z(T6) <> "" And T4 <> "" Then
v = Z(Arr(i, 6)) - 1: u = Y(Arr(i, 2)) - 1
Crr(v, u) = Crr(v, u) + 1
Y(TT) = 1
End If
PP:
Next
Sh2.[B2].Resize(UBound(Crr), UBound(Crr, 2)) = Crr
Sh2.Range(Sh2.[A1], Sh2.Cells(R + 1, C + 1)).Borders.LineStyle = 1
Application.Goto Sh2.[A1]
Set Y = Nothing
Set Z = Nothing
Set Arr = Nothing
Set Crr = Nothing
End Sub作者: Andy2483 時間: 2023-1-5 12:56