|
本帖最后由 一把小刀闯天下 于 2018-6-20 11:30 编辑
Option Explicit
Sub test()
Dim i, j, k, a, m, n, arr
With Sheets("源数据")
arr = .Range("a2:m" & .Cells(Rows.Count, "a").End(xlUp).Row + 1)
End With
ReDim brr(1 To UBound(arr, 1), 1 To 10 * UBound(arr, 2)) As String '一个家庭最多10人,自己修改
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j + 1, 9) = "户主" Or Len(arr(j + 1, 9)) = 0 Then
n = n + 1: m = 0
For a = i To j
For k = 1 To UBound(arr, 2)
m = m + 1: brr(n, m) = arr(a, k)
Next k, a
i = j: Exit For
End If
Next j, i
With Sheets("新表").[a2]
.Resize(Rows.Count - 1, UBound(brr, 2)).ClearContents
If n > 0 Then .Resize(n, UBound(brr, 2)) = brr
End With
End Sub
|
|