返回列表 上一主題 發帖

加班費計算

回復 1# mmggmm
  1. Private Sub Worksheet_Change(ByVal Target As Range) '月結
  2. If Intersect(Target, Union([A1], [C1])) Is Nothing Then Exit Sub
  3. Set d = CreateObject("Scripting.Dictionary")
  4. MyDay = [A1] & [C1]
  5. With Sheets("Main")
  6. For Each a In .Range(.[A2], .[A2].End(xlDown))
  7.    If Format(a, "yyyym") = MyDay Then
  8.      If IsEmpty(d(a.Offset(, 1).Value)) Then
  9.         d(a.Offset(, 1).Value) = Array(a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value, a.Offset(, 4).Value)
  10.         Else
  11.         ar = d(a.Offset(, 1).Value)
  12.         ar(2) = ar(2) + a.Offset(, 3): ar(3) = ar(3) + a.Offset(, 4)
  13.         d(a.Offset(, 1).Value) = ar
  14.         Erase ar
  15.      End If
  16.     End If
  17. Next
  18. Me.Range("A1").CurrentRegion.Offset(3).ClearContents
  19. If d.Count > 0 Then Me.[A3].Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
  20. End With
  21. End Sub
複製代碼
  1. Private Sub Worksheet_Change(ByVal Target As Range) '年結
  2. If Intersect(Target, [A1]) Is Nothing Then Exit Sub
  3. Set d = CreateObject("Scripting.Dictionary")
  4. MyYear = [A1]
  5. With Sheets("Main")
  6. For Each a In .Range(.[A2], .[A2].End(xlDown))
  7.    If Year(a) = MyYear Then
  8.      If IsEmpty(d(a.Offset(, 1).Value)) Then
  9.         d(a.Offset(, 1).Value) = Array(a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value, a.Offset(, 4).Value)
  10.         Else
  11.         ar = d(a.Offset(, 1).Value)
  12.         ar(2) = ar(2) + a.Offset(, 3): ar(3) = ar(3) + a.Offset(, 4)
  13.         d(a.Offset(, 1).Value) = ar
  14.         Erase ar
  15.      End If
  16.     End If
  17. Next
  18. Me.Range("A1").CurrentRegion.Offset(3).ClearContents
  19. If d.Count > 0 Then Me.[A3].Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
  20. End With
  21. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 5# mmggmm
這行Offset(3)錯誤
改成
Me.Range("A1").CurrentRegion.Offset(2).ClearContents
學海無涯_不恥下問

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題