返回列表 上一主題 發帖

[發問] 逐筆比對回傳資料

本帖最後由 jcchiang 於 2021-1-28 12:47 編輯

回復 1# 蘿蔔泥

試試看
Sub ex()
Dim d As Object
Dim a, b, x%
Set d = CreateObject("Scripting.Dictionary")
For Each b In Range(Sheets("登錄").[B3], Sheets("登錄").[B65536].End(3))
   For x = 0 To b.Offset(, 1) - 1
      With Sheets("特休天數")
         For Each a In Range(.[a2], .[a65535].End(3))
            If a = Sheets("登錄").[b1] And a.Offset(, 3) <= b + x And a.Offset(, 4) >= b + x Then                    
               If b.Offset(, 2) = "" Then   '將年度資料放入Sheets("登錄")
                  b.Offset(, 2) = a.Offset(, 7)
               Else
                   b.Offset(, 2) = b.Offset(, 2) & "/" & a.Offset(, 7)
               End If               
               a.Offset(, 8) = a.Offset(, 8) + 1    '將已休天數累計放入Sheets("特休天數")
               d(a & b + x) = Array(a, a.Offset(, 1), b.Offset(, -1), b + x, "1", a.Offset(, 7))
            End If
         Next
      End With
   Next
Next
Sheets("list").[a65535].End(3).Offset(1).Resize(d.Count, 6) = Application.Transpose(Application.Transpose(d.Items))
Set d = Nothing
End Sub

TOP

        靜思自在 : 口說好話、心想好意、身行好事。
返回列表 上一主題