Option Explicit
Sub test()
Dim arr, i, m, n
arr = Range("b3:d" & Cells(Rows.Count, "b").End(xlUp).Row)
ReDim brr(UBound(arr, 1), 1 To 7)
For i = 1 To UBound(arr, 1)
If Len(arr(i, 1)) Then n = n + 1
If n = 2 Then
m = m + 1
brr(m, 1) = arr(i, 3): brr(m, 2) = arr(i, 2): brr(m, 3) = arr(i, 1)
End If
If n = 3 Then
brr(m, 5) = arr(i, 3): brr(m, 6) = arr(i, 2): brr(m, 7) = arr(i, 1)
n = 0
End If
Next
brr(0, 1) = "三星": brr(0, 2) = "苹果": brr(0, 3) = "小米"
brr(0, 5) = "三星": brr(0, 6) = "苹果": brr(0, 7) = "小米"
With [h3]
.Resize(Rows.Count - 2, UBound(brr, 2)) = vbNullString
If m > 0 Then .Resize(m + 1, UBound(brr, 2)) = brr
End With
End Sub |