Run-time error '1004' while copying

2019-09-19 11:04发布

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.

The error pops up for the second line of code.

Can I get some insight please?

标签: excel vba
2条回答
对你真心纯属浪费
2楼-- · 2019-09-19 11:42

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")
查看更多
Root(大扎)
3楼-- · 2019-09-19 11:44

You forgot the "." before Cells (as you are within the With scope of the Sheet Data)

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

Tested the above example and now it works for me.

查看更多
登录 后发表回答