|
Sub 批量生成()
Application.ScreenUpdating = False
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Set dic_1 = CreateObject("scripting.dictionary")
Set dic_2 = CreateObject("scripting.dictionary")
With Sheets("生产经营性收支")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:h" & r)
End With
With Sheets("户主信息")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:d" & rs)
End With
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
dc(Trim(br(i, 1))) = br(i, 3)
End If
Next i
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Index > 3 Then sh.Delete
Next sh
Application.DisplayAlerts = True
For Each k In d.keys
n = 0: m = 0: dic_1.RemoveAll: dic_2.RemoveAll
ReDim arr(1 To UBound(ar), 1 To 12)
ReDim brr(1 To UBound(ar), 1 To 12)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = k Then
hz = ar(i, 2)
rs = dc(k)
If Trim(ar(i, 5)) <> "种植业" Then
n = n + 1
arr(n, 1) = ar(i, 3)
arr(n, 2) = ar(i, 7)
arr(n, 11) = ar(i, 8)
dic_1(ar(i, 3)) = dic_1(ar(i, 3)) + ar(i, 8)
Else
m = m + 1
brr(m, 1) = ar(i, 3)
brr(m, 2) = ar(i, 7)
brr(m, 11) = ar(i, 8)
dic_2(ar(i, 3)) = dic_2(ar(i, 3)) + ar(i, 8)
End If
End If
Next i
Sheets("模板").Copy after:=Sheets(Sheets.Count)
With ActiveSheet
.Name = hz & "_" & k
.[a2] = "户主姓名:" & hz & " 身份证号码: 家庭常住人口数:" & rs & " 人 "
If n > 0 Then
.[a7].Resize(n, UBound(arr, 2)) = arr
.[c27] = dic_1(1)
.[f27] = dic_1(2)
.[i27] = dic_1(3)
.[l27] = dic_1(4)
End If
If m > 0 Then
.[a33].Resize(m, UBound(arr, 2)) = brr
.[c48] = dic_2(1)
.[f48] = dic_2(2)
.[i48] = dic_2(3)
.[l48] = dic_2(4)
End If
End With
Next k
Sheets("生产经营性收支").Select
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
2
查看全部评分
-
|