返回列表 上一主題 發帖

[發問] 計算個別員工於週六上班次數

回復 4# hkyan
(注意:為了讓日期更具發展性, 刻意將你的樣本的統計欄位調到最左邊)
如下圖, 試試看:
  1. Option Explicit
  2. Private Sub CommandButton1_Click()
  3.     Dim i, j, lastRow, lastCol As Integer
  4.     Dim 距今 As Long
  5.     lastRow = [C65536].End(xlUp).Row
  6.     lastCol = [IV1].End(xlToLeft).Column
  7.     [A2].Resize(lastRow, 2) = ""
  8.     For i = 4 To lastCol
  9.         If Weekday(Cells(1, i), vbMonday) = 6 Then
  10.             距今 = Date - Cells(1, i)
  11.             For j = 2 To lastRow
  12.                 If Cells(j, i) <> "" Then
  13.                     Cells(j, 1) = Cells(j, 1) + 1   '週六加班日數+1
  14.                     Cells(j, 2) = 距今
  15.                 End If
  16.             Next
  17.         End If
  18.     Next
  19. End Sub
複製代碼

TOP

        靜思自在 : 受人點水之恩,須當湧泉以報。
返回列表 上一主題