- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
本帖最後由 GBKEE 於 2016-1-12 05:59 編輯
回復 14# 074063
也可以不用 字典物件.- Option Explicit
- '*** 類別有變動新增或減少在模組上端修改,不必修改成式碼***
- '如果我的類別有3~4組
- Const KeyWord = "VOX"
- '則區分時間皆在【O】類別前時間為17:20~19:20, 在【X】類別前時間為17:20~18:20....
- Const KeyTime = "17:20,~,19:20" & vbLf & "17:20,~,24:20" '& vbLf &......
- Dim Rng As Range
- Sub Ex_清除資料()
- Set Rng = Sheets("sheet1").Range("h7") '輸入的位置
- With Rng.CurrentRegion
- If Application.CountA(.Cells) > 0 Then .Clear
- End With
- End Sub
- Sub Ex_資料輸入()
- Dim Ar(0 To Len(KeyWord) - 1), i As Integer, R As Integer, E As Integer, Ar_Time As Variant
- Dim C As Integer
- Ex_清除資料
- Ar_Time = Split(KeyTime, vbLf) 'KeyTime字串分割為陣列
- Application.ScreenUpdating = False
- i = 2
- Do
- R = InStr(KeyWord, Rng.Parent.Cells(i, "C")) '備註欄的字串,在KeyWord中的順序
- If Rng.Parent.Cells(i, "C") <> "" And R >= 1 Then
- Ar(R - 1) = Ar(R - 1) & Rng.Parent.Cells(i, "B") & vbLf
- '依 KeyWord的字母順序 將姓名欄的資料,導入Ar中
- End If
- i = i + 1
- Loop Until Rng.Parent.Cells(i, "b") = "" 'B欄沒有資料
- '******姓名欄的資料,導入Ar中 完畢****
- i = 0
- For R = 0 To UBound(Ar)
- Ar(R) = Split(Ar(R), vbLf) '導入Ar中姓名欄資料,分割為陣列
- For C = 0 To UBound(Ar(R)) - 1
- With Rng.Offset(, i).Resize(3)
- .MergeCells = True
- .Orientation = xlVertical
- .Value = Ar(R)(C)
- End With
- i = i + 1
- Next
- If R < UBound(Ar) Then
- For E = 1 To 3
- With Rng.Offset(, i).Resize(, 2).Rows(E)
- .MergeCells = True
- .HorizontalAlignment = xlCenter
- .Value = "'" & Split(Ar_Time(R), ",")(E - 1)
- '陣列 Ar_Time
- End With
- Next
- End If
- i = i + 2
- Next
- With Rng.CurrentRegion.Font
- .Bold = True
- .ColorIndex = 25
- End With
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|