在excel中创建换行符

时间:2013-10-02 08:56:40

标签: excel excel-vba vba

我有一个文档,我想在行之间创建换行符以分组发票。

例如,我的文档显示:

H   INV 96579551
N   606R00103216L   2003-
H   INV 96579583
N   606R00103216L   2003-
H   INV 96579584
N   606R00103216L   2003-

但是我想创建一个允许我的文档看起来像的宏:

H   INV 96579551
N   606R00103216L   2003-

H   INV 96579583
N   606R00103216L   2003-


H   INV 96579584
N   606R00103216L   2003-

有人能给我任何提示吗? 感谢

1 个答案:

答案 0 :(得分:0)

希望这对您有用(假设您按排序顺序排列了分组行)

Sub Test()
    Set selectRows = Cells(3, 1) 'start from 3rd row
    For i = 3 To ActiveSheet.UsedRange.Rows.Count Step 2 'skip 2 rows (H & N group)
        Set selectRows = Union(selectRows, Cells(i, "A")) 'store the ODD cell references - starting from 3rd row
    Next i
    selectRows.EntireRow.Select 'select all the rows stored in the union reference
    Selection.Insert Shift:=xlDown 'simulate Ctrl+ to add a row
    Cells(1, 1).Select 'select the first cell - just to keep it clean :-)
End Sub