|
- Sub test()
- Dim r%, i%
- Dim arr, brr, zrr()
- m = 0
- With Worksheets("基础数据")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a4:d" & r)
- For i = 1 To UBound(arr)
- If arr(i, 3) = "户主" Then
- m = m + 1
- ReDim Preserve zrr(1 To 2, 1 To m)
- zrr(1, m) = i
- zrr(2, m) = i
- Else
- zrr(2, m) = i
- End If
- Next
- End With
- For Each ws In Worksheets
- If ws.Name <> "基础数据" And ws.Name <> "户表" Then
- ws.Delete
- End If
- Next
- For k = 1 To UBound(zrr, 2)
- Worksheets("户表").Copy after:=Worksheets(Worksheets.Count)
- With ActiveSheet
- .Name = arr(zrr(1, k), 2)
- m = 0
- For i = zrr(1, k) To zrr(2, k)
- m = m + 1
- .Cells(m + 5, 2) = arr(i, 2)
- .Cells(m + 5, 3) = arr(i, 4)
- .Cells(m + 21, 2) = arr(i, 2)
- .Cells(m + 21, 3) = arr(i, 4)
- .Cells(m + 36, 2) = arr(i, 2)
- .Cells(m + 36, 3) = arr(i, 4)
- Next
- End With
- Next
- End Sub
复制代码 |
|