|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
你的本意应该是把汇总表里的信息,按家庭户分拆成表格吧。我用了5家不重复名字的试了一下,希望对你有用。
Sub 生成户()
Dim sht As Worksheet, sht2 As Worksheet, rng As Range, hus As Integer, rens As Integer
Set sht = Worksheets("汇总表")
For Each rng In sht.Range("c2:c2890")
Application.DisplayAlerts = False
If rng = "本人或户主" Then
hus = hus + 1
rens = rng.Offset(0, 5)
Worksheets("模板").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = rng.Offset(0, 1)
Set sht2 = ActiveSheet
With sht2
If rens >= 3 Then
.Range("c4") = rng.Offset(0, 1)
.Range("f4") = rng.Offset(0, 3)
.Range("h4") = rng.Offset(0, 5)
.Range("c5") = rng.Offset(0, 2)
.Range("g5") = rng.Offset(0, 6)
.Range("c6") = rng.Offset(0, -1)
.Range("c9") = rng.Offset(1, 1)
.Range("d9") = rng.Offset(1, 0)
.Range("e9") = rng.Offset(1, 2)
.Range("c10") = rng.Offset(2, 1)
.Range("d10") = rng.Offset(2, 0)
.Range("e10") = rng.Offset(2, 2)
.Range("h3") = hus
ElseIf rens = 2 Then
.Range("c4") = rng.Offset(0, 1)
.Range("f4") = rng.Offset(0, 3)
.Range("h4") = rng.Offset(0, 5)
.Range("c5") = rng.Offset(0, 2)
.Range("g5") = rng.Offset(0, 6)
.Range("c6") = rng.Offset(0, -1)
.Range("c9") = rng.Offset(1, 1)
.Range("d9") = rng.Offset(1, 0)
.Range("e9") = rng.Offset(1, 2)
.Range("c10") = ""
.Range("d10") = ""
.Range("e10") = ""
.Range("h3") = hus
ElseIf rens = 1 Then
.Range("c4") = rng.Offset(0, 1)
.Range("f4") = rng.Offset(0, 3)
.Range("h4") = rng.Offset(0, 5)
.Range("c5") = rng.Offset(0, 2)
.Range("g5") = rng.Offset(0, 6)
.Range("c6") = rng.Offset(0, -1)
.Range("c9") = ""
.Range("d9") = ""
.Range("e9") = ""
.Range("c10") = ""
.Range("d10") = ""
.Range("e10") = ""
.Range("h3") = hus
End If
End With
sht2.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & hus & sht2.Name & ".xlsx"
ActiveWorkbook.Close
sht2.Delete
End If
Next
Application.DisplayAlerts = True
End Sub
|
评分
-
1
查看全部评分
-
|