Option Explicit
Sub test()
Dim arr, i, j, k, m
With Sheets("sheet1")
arr = .Range("a2:e" & .Cells(Rows.Count, "c").End(xlUp).Row + 1).Value
For i = 2 To UBound(arr, 1) - 1
If Len(arr(i, 1)) > Len(arr(i - 1, 1)) And Len(arr(i, 1)) > Len(arr(i + 1, 1)) Then
If Len(arr(i + 1, 1)) = 0 Then
For j = i + 1 To UBound(arr, 1) - 1
m = m + 1
arr(m, 1) = arr(i, 1): arr(m, 2) = arr(i, 2)
For k = 3 To UBound(arr, 2)
arr(m, k) = arr(j, k)
Next
If Len(arr(j + 1, 1)) > 0 Or j = UBound(arr, 1) - 1 Then i = j: Exit For
Next
Else
m = m + 1
For j = 1 To UBound(arr, 2)
arr(m, j) = arr(i, j)
Next
End If
End If
Next
End With
Sheets("实现效果").[a2].Resize(m, UBound(arr, 2)) = arr
End Sub |