|
源代码基础上改了一下,测试通过:
Sub test()
Dim r%, i%
Dim arr, brr
Dim d As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("scripting.dictionary")
Set d0 = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
With Worksheets("户信息")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a4:l" & r)
For i = 1 To UBound(arr)
If Not d0.exists(arr(i, 6)) Then
Set d0(arr(i, 6)) = CreateObject("scripting.dictionary")
End If
If arr(i, 11) = "户主" Then
d0(arr(i, 6))(0) = Array(arr(i, 3), arr(i, 4), arr(i, 5), arr(i, 8), arr(i, 6), arr(i, 9))
End If
d0(arr(i, 6))(arr(i, 8)) = arr(i, 11)
Next
End With
With Worksheets("工资性收入")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:y" & r)
For i = 1 To UBound(arr)
jd = Val(arr(i, 11))
If Not d.exists(arr(i, 6)) Then
Set d(arr(i, 6)) = CreateObject("scripting.dictionary")
End If
If Not d(arr(i, 6)).exists(arr(i, 13)) Then
ReDim brr(1 To 29)
brr(1) = arr(i, 13)
If d0.exists(arr(i, 6)) Then
If d0(arr(i, 6)).exists(arr(i, 13)) Then
brr(2) = d0(arr(i, 6))(arr(i, 13))
End If
End If
brr(3) = DateDiff("yyyy", CDate(Format(Mid(arr(i, 14), 7, 8), "0000-00-00")), Date)
Else
brr = d(arr(i, 6))(arr(i, 13))
End If
If jd = 1 Then
brr(4) = arr(i, 16) & arr(i, 17) & arr(i, 18) & arr(i, 19) & arr(i, 20)
brr(5) = arr(i, 21)
brr(6) = arr(i, 22)
brr(7) = DateDiff("d", arr(i, 23), arr(i, 24))
brr(8) = arr(i, 25)
Else
n = jd * 7 - 5
brr(n) = arr(i, 16) & arr(i, 17) & arr(i, 18) & arr(i, 19) & arr(i, 20)
brr(n + 3) = arr(i, 21)
brr(n + 4) = arr(i, 22)
brr(n + 5) = DateDiff("d", arr(i, 23), arr(i, 24))
brr(n + 6) = arr(i, 25)
End If
d(arr(i, 6))(arr(i, 13)) = brr
Next
End With
With Worksheets("生产经营性收支")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:p" & r)
End With
For i = 1 To UBound(arr)
jd = Val(arr(i, 11))
If Not d1.exists(arr(i, 6)) Then
Set d1(arr(i, 6)) = CreateObject("scripting.dictionary")
End If
If Not d1(arr(i, 6)).exists(jd) Then
Set d1(arr(i, 6))(jd) = CreateObject("scripting.dictionary")
End If
Select Case arr(i, 13)
Case "种植业", "林果业", "养殖业"
If Not d1(arr(i, 6))(jd).exists(arr(i, 13)) Then
Set d1(arr(i, 6))(jd)(arr(i, 13)) = CreateObject("scripting.dictionary")
End If
If Not d1(arr(i, 6))(jd)(arr(i, 13)).exists(arr(i, 14)) Then
ReDim crr(1 To 3, 1 To 1)
crr(1, 1) = arr(i, 14)
Else
crr = d1(arr(i, 6))(jd)(arr(i, 13))(arr(i, 14))
End If
If Right(arr(i, 12), 2) = "收入" Then
crr(2, 1) = crr(2, 1) + Val(arr(i, 16))
Else
crr(3, 1) = crr(3, 1) + Val(arr(i, 16))
End If
d1(arr(i, 6))(jd)(arr(i, 13))(arr(i, 14)) = crr
Case "加工业", "乡村旅游业"
If Not d1(arr(i, 6))(jd).exists(arr(i, 13)) Then
Set d1(arr(i, 6))(jd)(arr(i, 13)) = CreateObject("scripting.dictionary")
End If
xm = Right(arr(i, 12), 2)
d1(arr(i, 6))(jd)(arr(i, 13))(xm) = d1(arr(i, 6))(jd)(arr(i, 13))(xm) + arr(i, 16)
Case Else
Debug.Print arr(i, 13)
End Select
Next
With Worksheets("转移性收入")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:p" & r)
End With
For i = 1 To UBound(arr)
jd = Val(arr(i, 11))
If Not d2.exists(arr(i, 6)) Then
Set d2(arr(i, 6)) = CreateObject("scripting.dictionary")
End If
If Not d2(arr(i, 6)).exists(jd) Then
Set d2(arr(i, 6))(jd) = CreateObject("scripting.dictionary")
End If
If InStr(arr(i, 13), ">") = 0 Then
xx = arr(i, 13)
Else
xx = Mid(arr(i, 13), InStrRev(arr(i, 13), ">") + 1)
End If
d2(arr(i, 6))(jd)(xx) = d2(arr(i, 6))(jd)(xx) + Val(arr(i, 16))
Next
Set dz = CreateObject("scripting.dictionary")
For Each aa In d.keys
dz(aa) = 1
Next
For Each aa In d0.keys
dz(aa) = 1
Next
For Each aa In d1.keys
dz(aa) = 1
Next
For Each aa In d2.keys
dz(aa) = 1
Next
With Worksheets("模板表")
For Each aa In dz.keys
On Error Resume Next
Worksheets(aa).Delete
On Error GoTo 0
.Range("c2,f2,i2,l2,p2,t2,z2,a6:ac9,c12:e26,j12:l26,q12:s26,x12:z26,b28:h29,j28:o29,q28:v29,x28:ac29") = Empty
.Range("f12,g12,m12,n12,t12,u12,aa12,ab12") = "收入:" & Application.Rept(vbLf, 5) & "支出:"
.Range("h12,o12,v12,ac12") = "种类1:" & Application.Rept(vbLf, 4) & "收入1:" & Application.Rept(vbLf, 4) & "支出1:" & Application.Rept(vbLf, 4) & "种类2:" & Application.Rept(vbLf, 4) & "收入2:" & Application.Rept(vbLf, 4) & "支出2:"
drr = d0(aa)(0)
If d.exists(aa) Then
ReDim crr(1 To d(aa).Count, 1 To 29)
m = 0
For Each bb In d(aa).keys
If bb <> 0 Then
brr = d(aa)(bb)
m = m + 1
For j = 1 To UBound(brr)
crr(m, j) = brr(j)
Next
End If
Next
.Range("c2") = drr(0)
.Range("f2") = drr(1)
.Range("i2") = drr(2)
.Range("p2") = drr(3)
.Range("t2") = drr(4)
.Range("z2") = drr(5)
.Range("a6").Resize(UBound(crr), UBound(crr, 2)) = crr
End If
If d1.exists(aa) Then
For Each bb In d1(aa).keys
n = bb * 7 - 5
y = 0
For Each cc In Array("种植业", "林果业", "养殖业")
y = y + 1
If d1(aa)(bb).exists(cc) Then
m = 12
For Each dd In d1(aa)(bb)(cc).keys
crr = d1(aa)(bb)(cc)(dd)
.Cells(m, n + y).Resize(UBound(crr), UBound(crr, 2)) = crr
m = m + 3
Next
End If
Next
y = 0
For Each cc In Array("加工业", "乡村旅游业")
y = y + 1
If d1(aa)(bb).exists(cc) Then
.Cells(12, n + y + 3) = "收入:" & vbLf & IIf(d1(aa)(bb)(cc).exists("收入"), d1(aa)(bb)(cc)("收入") & vbLf, vbLf) & "支出:" & vbLf & IIf(d1(aa)(bb)(cc).exists("支出"), d1(aa)(bb)(cc)("支出"), "")
End If
Next
Next
End If
If d2.exists(aa) Then
For Each bb In d2(aa).keys
n = Application.Choose(bb, 2, 10, 17, 24)
ReDim frr(1 To 2, 1 To d2(aa)(bb).Count)
y = 0
For Each cc In d2(aa)(bb).keys
y = y + 1
frr(1, y) = cc
frr(2, y) = d2(aa)(bb)(cc)
Next
.Cells(28, n).Resize(UBound(frr), UBound(frr, 2)) = frr
Next
End If
shtname = drr(3)
On Error Resume Next
Worksheets(shtname).Delete
On Error GoTo 0
.Copy after:=Worksheets(Worksheets.Count)
With ActiveSheet
.Name = shtname
End With
Next
End With
End Sub
|
评分
-
1
查看全部评分
-
|