|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这样就可以了- Option Explicit
- Sub test()
- Dim arr, i&, m&, r&
- With Sheet1
- r = .Cells(Rows.Count, 4).End(3).Row
- arr = .Range("A2:E" & r)
- End With
- ReDim brr(1 To UBound(arr), 1 To 5)
- m = 0
- For i = 1 To UBound(arr)
- '
- If m > 1 Then
- If Not (arr(i, 2) = "户主" And arr(i - 1, 2) = "") Then m = m + 1
- Else
- m = m + 1
- End If
-
-
- If arr(i, 2) = "户主" Then
- brr(m, 1) = arr(i, 5)
- brr(m, 2) = arr(i, 3)
- brr(m, 3) = arr(i, 4)
- Else
- brr(m - 1, 4) = arr(i, 3)
- brr(m - 1, 5) = arr(i, 4)
- End If
- Next
- With Sheet2.[a3]
- .CurrentRegion.Offset(3).ClearContents
- .Resize(m, 5) = brr
- End With
- End Sub
复制代码
|
|