|
Sub insert_copy()
Dim rg As Range
Dim tg As Range
Set tg = ActiveSheet.Range("a:a").SpecialCells(xlCellTypeConstants, 23)
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
For Each rg In tg '确定每个需要插入的单元格,并记录下来,避免插入后发生位置变动
If rg.MergeArea.Row = rg.Row Then
i = i + 1
dic.Add i, rg.MergeArea
End If
Next
For Key = 1 To dic.Count
Dim tp As Integer
With dic(Key)
rg_count = .Count
If rg_count < 8 Then
first = rg_count
Do Until rg_count = 8
If rg_count = first Then
.Rows(rg_count).EntireRow.Copy
.Rows(rg_count).EntireRow.Insert Shift:=xlDown
.Rows(rg_count + 1).Offset(, 4).Resize(1, 4).ClearContents
Else: .Rows(rg_count).EntireRow.Insert
End If
rg_count = rg_count + 1
Loop
End If
End With
Next
End Sub |
|