Excel的VBA如下: Option Explicit Sub 插入空行() Dim arr '数组 Dim bend As Long bend = Range("b:b").Rows.Count '取b列的总行数 bend = Range("b" & bend).End(xlUp).Row '取b列有数的最后一行 arr = Range("a2:b" & bend) '数组赋值 Dim j As Long, nextA As String Dim i As Long, k As Long Dim no As Long, e As Long ReDim newarr(1 To UBound(arr) * 20, 1 To 2) i = 1: k = 0 nextA = Range("b2") For j = 1 To UBound(arr) If arr(j, 2) = nextA Then k = k + 1 Else no = k Mod 20 If no <> 0 Then For e = 1 To 20 - no newarr(i, 2) = "" newarr(i, 1) = "" i = i + 1 Next k = 1 Else k = 0 End If End If newarr(i, 1) = arr(j, 1) newarr(i, 2) = arr(j, 2) i = i + 1 nextA = arr(j, 2) Next Range("c2:d" & UBound(newarr)) = newarr '为方便放到C列。你可以放在原来的A2的位置,即: 'Range("a2:b" & UBound(newarr)) = newarr End Sub
|