|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 数据源()
Dim s, ds, i&, arrY, arrPovit(), dic, k&, m&, n&, u, rng As Range
Dim sdate As Date
Set ds = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
arrY = Array("30天以内", "30-60天", "60-180天", "180-360天", "1-2年", "2-3年", "3-4年", "4-5年", "5年以上")
s = Sheets("数据源").Range("a3").CurrentRegion.Offset(1)
sdate = ThisWorkbook.Worksheets("帐龄分析").Range("k1").Value
For i = 1 To UBound(s) - 1
Select Case sdate - s(i, 13)
Case Is < 30: s(i, 13) = arrY(0): Case 31 To 60: s(i, 13) = arrY(1)
Case 61 To 180: s(i, 13) = arrY(2): Case 181 To 360: s(i, 13) = arrY(3)
Case 361 To 720: s(i, 13) = arrY(4): Case 721 To 1080: s(i, 13) = arrY(5)
Case 1081 To 1440: s(i, 13) = arrY(6): Case 1441 To 1800: s(i, 13) = arrY(7)
Case Is > 1800: s(i, 13) = arrY(8)
End Select
Next
ReDim arrPovit(1 To UBound(s), 1 To 11)
For i = 0 To UBound(arrY)
ds(arrY(i)) = i + 3
Next
For i = 1 To UBound(s) - 1
If dic.exists(s(i, 6)) = True Then
u = s(i, 10) - s(i, 11)
arrPovit(dic(s(i, 6)), 2) = arrPovit(dic(s(i, 6)), 2) + u
For m = 11 To 3 Step -1
If u * arrPovit(dic(s(i, 6)), m) < 0 Then
u = u + arrPovit(dic(s(i, 6)), m)
If u * (s(i, 10) - s(i, 11)) > 0 Then
arrPovit(dic(s(i, 6)), m) = 0
ElseIf u * (s(i, 10) - s(i, 11)) <= 0 Then
arrPovit(dic(s(i, 6)), m) = u
GoTo Line
End If
End If
Next m
arrPovit(dic(s(i, 6)), ds(s(i, 13))) = arrPovit(dic(s(i, 6)), ds(s(i, 13))) + u (提示这里下标越界)
Else
k = k + 1: dic(s(i, 6)) = k: arrPovit(k, 1) = s(i, 6): arrPovit(k, 2) = s(i, 10) - s(i, 11): arrPovit(k, ds(s(i, 13))) = s(i, 10) - s(i, 11)
End If
Line: Next
ReDim s(1 To UBound(arrPovit), 1 To 11)
k = 0
For i = 1 To UBound(arrPovit)
If Abs(arrPovit(i, 2)) > 0.05 Then
k = k + 1
For m = 1 To 11
s(k, m) = arrPovit(i, m)
Next m
End If
|
|