Option Explicit
Sub TEST()
Dim Brr, Crr, Y, N&, i&, j&
'↑宣告變數
Set Y = CreateObject("Scripting.Dictionary")
'↑令Y變數是 字典
Brr = Range([C1], [A65536].End(xlUp))
'↑令Brr變數是 二維陣列,以A~C欄資料帶入
For i = 2 To UBound(Brr)
'↑設順迴圈
If Y(Brr(i, 3)) = "" Then N = N + 1: Y(Brr(i, 3)) = N
'↑令以字典紀錄班別在結果陣列Crr的欄位
Next
ReDim Crr(1 To UBound(Brr), 1 To 2 + N)
'↑宣告Crr變數是 二維空陣列,縱向範圍同Brr陣列,橫向從1到(2+N)
For i = 1 To UBound(Brr)
'↑設順迴圈
Crr(i, 1) = Brr(i, 1): Crr(i, 2) = Brr(i, 2)
'↑令日期帶入Crr第1欄,'↑令時間帶入Crr第2欄
If i = 1 Then
'↑如果是Brr第1列!就把班別標題列寫入Crr陣列第1列
For j = 1 To N: Crr(1, j + 2) = Y.KEYS()(j - 1): Next
GoTo i01
'↑標題列處理完,不必處理後續細節,所以跳到標示i01位置繼續執行
End If
Crr(i, Y(Brr(i, 3)) + 2) = "V"
'↑令Crr陣列正確班別位置欄寫入 "V"
i01: Next
With [E1].Resize(UBound(Crr), 2 + N)
.EntireColumn.Clear
'↑令結果欄舊資料整欄清除
.Value = Crr
'↑令以Crr陣列值貼入這With的範圍
Intersect(.Cells, [E:E]).NumberFormatLocal = "yyyy/m/d"
Intersect(.Cells, [F:F]).NumberFormatLocal = "hh:mm:ss"
.Borders.LineStyle = 1
.EntireColumn.AutoFit
'↑處理格式
End With
Set Y = Nothing: Erase Brr, Crr
'↑釋放變數
End Sub