我编写了一个vba脚本,以便在excel工作表中插入一定数量的新行。 该代码可以完成他的工作,除非剪贴板不为空。
执行此脚本之前,是否有任何脚本可用于清除剪贴板?
谢谢!
下面没有剪贴板检查的代码。
If ActiveSheet.Name <> "Worksheet A" Then
MsgBox "This macro only works in worksheet A"
Else
Dim Rng As Integer
Dim k As Integer
Dim R As Long
R = Selection.Row + 1
Rng = InputBox("Amount of rows?")
For k = 1 To Rng
Rows(R).Insert Shift:=xlDown
Next
End If
答案 0 :(得分:0)
在运行插入操作之前,请先关闭Application.CutCopyMode
:
If ActiveSheet.Name <> "Worksheet A" Then
MsgBox "This macro only works in worksheet A"
Else
Dim Rng As Integer
Dim k As Integer
Dim R As Long
R = Selection.Row + 1
Rng = InputBox("Amount of rows?")
Application.CutCopyMode = False
For k = 1 To Rng
Rows(R).Insert Shift:=xlDown
Next
End If