- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 20# b9208
附檔 Ex()程序不是 8# 的Ex()程序- Option Explicit
- Dim D(1 To 3) As Object, 週次 As Object, Ar ' 'Dim : 此模組的私用變數(僅此模組可用)
- Sub EX()
- Dim i As Integer, ii As Integer, M As String, Rng As Range, 統計單位 As Variant
- Set D(1) = CreateObject("scripting.dictionary") '字典物件
- Set D(2) = CreateObject("scripting.dictionary")
- Set D(3) = CreateObject("scripting.dictionary")
- Set 週次 = CreateObject("scripting.dictionary")
- With Sheets("統計")
- i = Application.CountA(.[b4:b13])
- 統計單位 = Join(Application.Transpose(.Range(.[b4], .[b4].Offset(i - 1))), ",") '統計單位=QWE,ASD
- End With
- With Sheets("明細")
- i = 6
- Do While .Cells(i, "D") <> ""
- ' "," & 統計單位 & "," -> ,QWE,ASD,
- If InStr("," & 統計單位 & ",", "," & .Cells(i, "F") & ",") Then '比對到 ,QWE, ,ASD, .....
- M = .Cells(i, "D") & .Cells(i, "E") & .Cells(i, "F") & .Cells(i, "L")
- If D(3)(M) = "" Then ' *** 這裡判斷4欄都相同為一筆資料 ****
- D(3)(M) = 0
- If InStr("," & 週次(.Cells(i, "F").Value) & ",", "," & Mid(.Cells(i, "E"), 1, 4)) & "," = 0 Then '統計單位: 比對週次不存在, .....
- 週次(.Cells(i, "F").Value) = IIf(週次(.Cells(i, "F").Value) = "", "", 週次(.Cells(i, "F").Value) & ",") & Mid(.Cells(i, "E"), 1, 4)
- End If
- M = .Cells(i, "D") & Mid(.Cells(i, "E"), 1, 4) & .Cells(i, "F")
- D(1)(M) = D(1)(M) + 1 '全部
- M = .Cells(i, "D") & Mid(.Cells(i, "E"), 1, 4) & .Cells(i, "F") & .Cells(i, "L")
- D(2)(M) = D(2)(M) + 1 '區域
- End If
- End If
- i = i + 1
- Loop
- End With
- With Sheets("統計")
- .[F:IQ].Clear
- For i = 0 To Application.CountA(.Range("B4:B13")) - 1
- Ar = Array("全部", "單位", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "小計")
- If i = 0 Then
- Set Rng = .[F3]
- Else
- Set Rng = .Cells(.Rows.Count, "F").End(xlUp).Offset(6) '每張表格間隔五列
- End If
-
- 週次(.Range("B4").Offset(i).Value) = Split(週次(.Range("B4").Offset(i).Value), ",")
- '取得統計單位之週次
-
- 表格製造 Rng, .Range("B4").Offset(i)
- 表格統計 Rng.CurrentRegion
-
- For ii = 0 To Application.CountA(.Range("B18:B21")) - 1
- Set Rng = .Cells(.Rows.Count, "F").End(xlUp).Offset(6) '每張表格間隔五列
- Ar(0) = .[B18].Offset(ii)
- 表格製造 Rng, .Range("B4").Offset(i)
- 表格統計 Rng.CurrentRegion
- Next
- Next
- End With
- End Sub
複製代碼 |
|