返回列表 上一主題 發帖

[發問] 考勤表VBA難題求助

回復 13# missbb
字典物件,也可試試看.
  1. Option Explicit
  2. Sub Ex()
  3.     Dim xDATE As Range, i, Rng As Range
  4.     Dim D As Object, K, X As Long, Ar As Variant
  5.     Set xDATE = Sheets("Attendance Report").[J3]  '輸入報表首日之前1日日期 的儲存格
  6.     With Sheets("data")  '資料工作表
  7.         Set Rng = .[D4] '資料開使的儲存格
  8.         X = 0
  9.         Do While Rng <> ""
  10.             Set D = CreateObject("SCRIPTING.DICTIONARY")  '設立變數 :字典物件
  11.             i = 1
  12.             Do While Rng.Offset(i - 1) = Rng  'Employee  上下列相同
  13.                 With Rng.Offset(i - 1)
  14.                     If D.EXISTS(.Range("C1").Value) Then    '如果在 Dictionary 物件中指定的關鍵字存在,傳回 True,
  15.                         D(.Range("C1").Value) = D(.Range("C1").Value) & "," & .Range("D1").Text
  16.                     Else
  17.                         D(.Range("C1").Value) = .Range("D1").Text
  18.                         '.Range("C1").Value 為日期值
  19.                     End If
  20.                  End With
  21.                 i = i + 1
  22.             Loop
  23.             For Each K In D.KEYS  'Keys 方法 傳回一個陣列,該陣列包含一個 Dictionary 物件中的全部既存的的關鍵字。
  24.                 Ar = Split(D(K), ",") 'Keys的內容
  25.                 With xDATE.Offset(, K - xDATE)  'k 為日期值
  26.                     .Parent.Cells(.Row + X + 1, "a") = Rng.Range("b1").Value
  27.                     .Parent.Cells(.Row + X + 1, "d").Resize(20) = Rng
  28.                     If UBound(Ar) = 1 Then
  29.                         .Cells(X + 3) = Ar(0)
  30.                         .Cells(X + 4) = Ar(1)
  31.                     ElseIf UBound(Ar) = 2 Then
  32.                         .Cells(X + 3) = Ar(0)
  33.                         .Cells(X + 4) = Ar(2)
  34.                         .Cells(X + 10) = Ar(1)
  35.                     ElseIf UBound(Ar) = 3 Then
  36.                         .Cells(X + 3) = Ar(0)
  37.                         .Cells(X + 4) = Ar(3)
  38.                         .Cells(X + 10) = Ar(1)
  39.                         .Cells(X + 11) = Ar(2)
  40.                     ElseIf UBound(Ar) = 4 Then
  41.                         .Cells(X + 3) = Ar(0)
  42.                         .Cells(X + 4) = Ar(4)
  43.                         .Cells(X + 10) = Ar(1)
  44.                         .Cells(X + 11) = Ar(2)
  45.                     End If
  46.                 End With
  47.             Next
  48.             X = X + 20
  49.             Set Rng = Rng.Offset(i)
  50.         Loop
  51.     End With
  52. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 18# missbb

你附檔的ee data 員工只有2位,可多舉一些.看看
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 人要知福、惜福、再造福。
返回列表 上一主題