我在Excel中有一个宏,但当我尝试使用Selection.PasteSpecial
进行粘贴时,它显示错误1004。
如果我在Office 2010中尝试使用相同的宏,则可以使用Office 365此错误。
调试器在此行中显示错误:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
该模块的完整代码是:
Sub MoveData_Activations()
MoveData_Activations Macro
Dim dayCount As Integer
Dim startCell As String
Dim curCellRef As String
dayCount = 13
startCell = "B3"
If MsgBox("Are you sure you want to rollover the data for a new date?", vbYesNo, "Confirm rollover") = vbYes Then
ActiveSheet.Protect UserInterfaceOnly:=True
Range(startCell).Select
ActiveCell.Cells(-1, 6).Copy
ActiveCell.Cells(-1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
curCellRef = Range(startCell).Address
For i = 1 To dayCount
CopyData curCellRef, False, 6, 24, 2
curCellRef = ActiveCell.Cells(1, 6).Address
Next i
CopyData curCellRef, True, 6, 24, 2
End If
End Sub
答案 0 :(得分:0)
在剪贴板中复制内容总是很费时,可能是其他程序使用了它们,因此错误或内存会以某种方式混乱。
简而言之,更改这些行:
来自:
Range(startCell).Select
ActiveCell.Cells(-1, 6).Copy
ActiveCell.Cells(-1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
要:
Range(startCell).Offset(-1, 6).Copy destination:=Range(startCell).Offset(-1, 1)