- Sub 插入空白行()
- Dim LastRow As Long
- Dim i As Integer, j As Integer, k As Integer, n As Integer
- Dim Arr, Result()
- LastRow = Range("A1").CurrentRegion.Rows.Count
- Arr = Range("A3:G" & LastRow)
- n = LastRow - 2
- ReDim Result(1 To 2 * n, 1 To 7)
- i = 1: j = 1
- On Error Resume Next
- Do
- k = k + 1
- If Arr(i, 1) = Arr(j, 5) Then
- Result(k, 1) = Arr(i, 1): Result(k, 2) = Arr(i, 2): Result(k, 3) = Arr(i, 3)
- Result(k, 5) = Arr(j, 5): Result(k, 6) = Arr(j, 6): Result(k, 7) = Arr(j, 7)
- i = i + 1: j = j + 1
- ElseIf Arr(i, 1) < Arr(j, 5) Or j > n Then
- Result(k, 1) = Arr(i, 1): Result(k, 2) = Arr(i, 2): Result(k, 3) = Arr(i, 3)
- i = i + 1
- ElseIf Arr(i, 1) > Arr(j, 5) Or i > n Then
- Result(k, 5) = Arr(j, 5): Result(k, 6) = Arr(j, 6): Result(k, 7) = Arr(j, 7)
- j = j + 1
- End If
- Loop Until i > n And j > n
- Range("A3").Resize(k, 7) = Result
- Range("A3").CurrentRegion.Borders.Weight = xlThin
- End Sub
复制代码 |