|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请试用。使用方法是把鼠标放在你要求和的列(可多列一起计算,因为有时候请假什么的,某天没有计算,可以一次计算多天),运行代码即可。
Sub test()
Dim rng1 As Range, rng2 As Range, c As Range, c2 As Range
Set d = CreateObject("Scripting.Dictionary")
If Selection.Column < 6 Then Exit Sub
Set rng1 = Intersect(Range(Columns(Selection.Column), Columns(Selection.Column + Selection.Columns.Count - 1)), Range("1:1"))
Set rng2 = Range("c2:c" & Range("c" & Rows.Count).End(3).Row)
For Each c In rng1
If c.Column = 6 Then dt = dt & "/" & CLng(CDate(Right(c, 10))) Else dt = dt & "/" & CLng(c)
Next
For Each c In rng2
If Len(c) Then s = s & "/" & c
Next
arr = Sheet2.Range("a1").CurrentRegion
For i = 2 To UBound(arr)
If InStr(s, arr(i, 1)) > 0 And InStr(dt, CLng(arr(i, 3))) > 0 Then
d(arr(i, 1) & "/" & CLng(arr(i, 3))) = d(arr(i, 1) & "/" & CLng(arr(i, 3))) + arr(i, 7)
End If
Next
For Each c In rng2
For Each c2 In rng1
If c2.Column = 6 Then k = c & "/" & CLng(CDate(Right(c2, 10))) Else k = c & "/" & CLng(c2)
If d.exists(k) Then Cells(c.Row, c2.Column) = d(k) Else Cells(c.Row, c2.Column) = 0
Next
Next
Set d = Nothing
End Sub
|
|