简体   繁体   English

复制时出现运行时错误“1004”

[英]Run-time error '1004' while copying

I'm getting the infamous Run-time error when I run this code, and I don't understand why:当我运行这段代码时,我遇到了臭名昭著的运行时错误,我不明白为什么:

With ThisWorkbook.Sheets("Data") .Range(Cells(row1, column1), Cells(row2, column1)).Copy End With

row1, column1 and row2 are all defined as Integers. row1、column1 和 row2 都定义为整数。

The error pops up for the second line of code.错误弹出第二行代码。

Can I get some insight please?我可以得到一些见解吗?

You forgot the "."你忘记了“。” before Cells (as you are within the With scope of the Sheet Data)Cells (如你是内With所述表数据的范围)

With ThisWorkbook.Sheets("Sheet2")
    .Range(.Cells(1, 1), .Cells(2, 2)).Copy
End With

Tested the above example and now it works for me.测试了上面的例子,现在它对我有用。

Where are you coping the range to.你在哪里应对范围。 The proper format is正确的格式是

source.copy destination源.复制目标

Sheets("Count").Range("C2:D3").Copy Sheets("Count").Range("E2:F3")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM