- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 136
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-6-5
               
|
13#
發表於 2010-12-30 15:34
| 只看該作者
回復 12# asus103 - Sub Ex()
- Dim A As Range, Ar(), C, d As Object, d1 As Object, d2 As Object, r&, MyClass$, Ky, s%, i%
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- With Sheets("Sheet1")
- For Each A In .Range(.[B1], .Cells(.Cells.Rows.Count, 2).End(xlUp))
- If A Like "*班" Then MyClass = A.Value
- If Replace(A.Value, " ", "") = "學號" Then Ar = .Range(A, A.End(xlToRight)).Value
- If Val(A.Value) <> 0 And InStr(A, "-") = 0 Then
- s = 0
- For Each C In Ar
- If C <> "" Then d1(C) = ""
- If C = "姓名" Then d1("班級") = "": d(A & "班級") = Replace(Replace(Replace(Replace(Replace(Replace(MyClass, "高", ""), "年", ""), "班", ""), "三", 3), "二", 2), "一", 1)
- d2(A.Value) = ""
- d(A & C) = IIf(s > 5, "", "'") & A.Offset(, s).Text
- s = s + 1
- Next
- End If
- Next
- End With
- With Sheets("Sheet4")
- .Cells = ""
- r = 2
- .[A1].Resize(, d1.Count) = d1.KEYS
- For Each Ky In d2.KEYS
- For i = 1 To d1.Count
- .Cells(r, i) = IIf(d(Ky & .Cells(1, i)) = "", -1, d(Ky & .Cells(1, i)))
- Next
- r = r + 1
- Next
- End With
- End Sub
複製代碼 |
|