|
Sub 分配()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("登记表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:f" & rs)
End With
With Sheets("明细表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
.Range(.Cells(2, 3), .Cells(r, y)) = Empty
ar = .Range(.Cells(1, 1), .Cells(r, y))
For j = 3 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
zd = Format(ar(1, j), "yyyy/m")
d(zd) = j
End If
Next j
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
d(Trim(ar(i, 2))) = i
End If
Next i
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" And Trim(br(i, 3)) <> "" Then
If IsDate(br(i, 2)) And IsDate(br(i, 3)) Then
ys = DateDiff("m", br(i, 2), br(i, 3)) + 1
xh = d(Trim(br(i, 1)))
zd = Format(br(i, 2), "yyyy/m")
zf = Format(br(i, 3), "yyyy/m")
ks = d(zd)
js = d(zf)
If xh <> "" And ks <> "" And js <> "" Then
ar(xh, 3) = br(i, 4)
For j = ks To js
ar(xh, j) = br(i, 4) / ys
Next j
End If
End If
End If
Next i
.Range(.Cells(1, 1), .Cells(r, y)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
2
查看全部评分
-
|