插入空白单元格
需求
- 去重后的数据在每一个单元格下插入指定的空白行
- 实现的示意视频
方案思路
- 选中一列单元格区域,然后从下方插入,为保证插入的空白在被插入单元格的下方,需要从被插入单元格的下方开始插入
代码实现
Sub insert_blank()
'在选中的单元格区域的每行下插入指定数量的空白行
On Error GoTo a
Set rng = Application.InputBox(prompt:="请选择需要插入空白单元格的连续区域?", Title:="输入框", Default:=Selection.Address, Type:=8) '选择单元格区域
a:
If TypeName(rng) <> "Range" Then
Exit Sub
End If
add1 = rng.Address
arr1 = Split(Join(Split(add1, ":"), ""), "$")
n = Application.InputBox(prompt:="想插入几行空白单元格?", Title:="输入框", Type:=1)
If n = "False" Then
Exit Sub
End If
For i = arr1(4) + 1 To arr1(2) + 1 Step -1
For j = 1 To n
Range(arr1(1) & CStr(i) & ":" & arr1(3) & CStr(i)).Insert shift:=xlDown '插入单元格,活动单元格向下移动
Next
Next
End Sub