'4行为1个数据块,第3行开始
Option Explicit
Sub 按钮2_单击()
Dim arr, i, j, m, n, row, t
row = Cells(Rows.Count, "b").End(xlUp).row
t = row - 2
If t Mod 4 > 0 Then row = row + (4 - t Mod 4)
arr = Range("b3:d" & row)
ReDim brr(UBound(arr, 1), 1 To 7)
For i = 1 To UBound(arr, 1) Step 4
m = m + 1
brr(m, 1) = arr(i + 1, 3): brr(m, 2) = arr(i + 1, 2): brr(m, 3) = arr(i + 1, 1)
brr(m, 5) = arr(i + 2, 3): brr(m, 6) = arr(i + 2, 2): brr(m, 7) = arr(i + 2, 1)
Next
brr(0, 1) = "三星": brr(0, 2) = "苹果": brr(0, 3) = "小米"
brr(0, 5) = "三星": brr(0, 6) = "苹果": brr(0, 7) = "小米"
For i = 1 To m '去除空行
For j = 1 To UBound(brr, 2)
If Len(brr(i, j)) Then Exit For
Next
If j < UBound(brr, 2) + 1 Then
n = n + 1
For j = 1 To UBound(brr, 2): brr(n, j) = brr(i, j): Next
End If
Next
With [h3]
.Resize(Rows.Count - 2, UBound(brr, 2)) = vbNullString
If n > 0 Then .Resize(n + 1, UBound(brr, 2)) = brr
End With
End Sub |